Solved

Several Bugs on a script

Posted on 2002-07-17
5
164 Views
Last Modified: 2010-03-05
Hello! it's me again... this is my first week using perl.
Sorry about my english... I'm learning that to!

I'm making a script to manage some data.  
So I posting it here so you be able to see what it's wrong.

Then if fixing it still no output I will send you all the files to reproduce it on your pc.

I mean! just give it an over view.  An tell me what to fix.

The other files just got the anchors
<!--hora -->  
<!--nacional -->

-------------------------------------
Here is the file that colects the input
-------------------------------------
<html>
<title>Breaking News Updater PRO 1.0  Build# 2002</title>
<body bgcolor="#FFFFFF">
<form action="../../cgi-bin/uhora/uhora.cgi" method="post" enctype="multipart/form-data" name="Uhora" id="Uhora">
 <p> Seleccione una secci&oacute;n<br>
   <select name="seccion">
     <option value="nacional">Nacional</option>
     <option value="mundo">Mundo</option>
     <option value="negocios">Negocios</option>
     <option value="internacional">Internacional</option>
   </select>
 </p>
 <p>Titulo de la nota:<br>
   <input name="titulo" type="text" size="60">
 </p>
 <p>Contenido de la nota:<br>
   <textarea name="descripcion" cols="70" rows="20" wrap="PHYSICAL"></textarea>
 </p>
 <p>Nota anterior relacionada:<br>
   Texto:
   <input name="texto" type="text" id="texto" size="30">
   Url:
   <input name="link" type="text" id="link" size="30">
 </p>
 <p>
   <input type="reset" value="Borrar">
   <input type="submit"  value="Enviar">
 </p>
 </form>
</html>

-------------------------------------
Here is the script
-------------------------------------
#!/usr/bin/perl

$path = "C:/root/html/uhora";
$file = "uhora_$seccion.shtml";
$seccion = param('seccion');
$uhora_anchor = "<!--$seccion -->";
$titulo = param('titulo');
$descripcion = param('descripcion');
$descripcion =~ s/\r\n/<br>/g;
$text = param('texto');
$links = param('link');
$url = "<a href="$links">$text</a>";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
     if($hour < 12) {
          $ext = 'a.m.';
     }
     else {
          $ext = 'p.m.';
     }
     if($hour > 12) {
          $hour = $hour - 12;
     }
     if($min < 10) {
          $min = 0 . $min;
     }
     if($sec < 10) {
          $sec = 0 . $sec;
     }
$hora = "$hour:$min $ext";

#------------------------------------------------------------------------------
# Imprime la noticia en el archivo archivo uhora_****.shtml.
#------------------------------------------------------------------------------
     open (DATA, "$path/$file");
          while($line = <DATA>) {
          $contents .= $line;
          }
          $noticia = <<END;
          <a name="$min$sec"></a><span class="uhora_tit">$titulo</span><br>
          <span class="uhora_fecha">($hora)</span>
          <span class="uhora_int">$descripcion</span><br>
          if $links eq "www";{
          $url
          }
          else {
          }
          <a href="#top">Inicio</a>
          <hr size="1" noshade>
          END
          $contents =~ s|$uhora_anchor|$uhora_anchor$noticia|is;
          open (DATA, ">$path/$file");
          print DATA $contents;
     close(DATA);

#------------------------------------------------------------------------------
# Coloca titulo en el archivo indice.inc
#------------------------------------------------------------------------------
     $contents = "";
     open (DATA, "$path/indice.inc");
     while($line = <DATA>) {
          $contents .= $line;
          }
          $indice_no = <<END;
          <!--$seccion --><a href=../uhora/uhora_$archivo.shtml#$min$sec><span class=\"uhora\">$titulo</span></a><p>
          END
          $indice_yes = <<END;
          <a href=../uhora/uhora_$archivo.shtml#$min$sec><span class=\"uhora\">$titulo</span></a><p>
          END
          if ($contents =~ $uhora_anchor;){
               $contents =~ s|$uhora_anchor|$uhora_anchor$indice_yes|is;
               open(DATA, ">$path/uhora.inc");
               print DATA $contents;
               }
               else {
                    $contents =~ s|$contents|$indice_no$contents|is;
                    open(DATA, ">$path/uhora.inc");
                    print DATA $contents;
               }
          close(DATA);    

#------------------------------------------------------------------------------
# Coloca la hora en el archivo indice.inc
#------------------------------------------------------------------------------
     $contents = "";
     $hora_anchor = "<!--hora -->";
     open (DATA, "$path/indice.inc");
     $horadata = <<END;
          <span class=\"uhora_time\">$hora</span><br><br>
          END
     while($line = <DATA>) {
          $contents .= $line;
          }
          if($wday eq 0) {
               close(DAFILE);
          }
          if($wday eq 6) {
               close(DAFILE);
          }
          if($hour eq 5) {
               close(DAFILE);
          }
          if($hour eq 6) {
               close(DAFILE);
          }
     else     {
          $contents =~ s|$hora_anchor|$hora_anchor$horadata<br>|is;
          open (DATA, ">$path/$file");
          print DATA $contents;
          close DATA
     }
#------------------------------------------------------------------------------
# Imprime respuesta del script y regresa.
#------------------------------------------------------------------------------
print <<END;
Content-Type: text/html\n\n

<html>
<META HTTP-EQUIV='REFRESH' CONTENT='2;URL=http://localhost/html/uhora/update.html'>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Actualizando el archivo uhora_$seccion.shtml
<br>
 Porfavor espere...</font></p>
<p align="center">&nbsp;</p>
<p align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Breaking News Updater 1.0 Build# 2502<br>
BlueWork Development Studio. All rights reserved 2002.</font></p>
</body>
</html>
END
0
Comment
Question by:Silentbob19
  • 3
5 Comments
 

Author Comment

by:Silentbob19
Comment Utility
Some how when I submit the first time, all the initial < where missing...

Here it is again... sorry
0
 

Author Comment

by:Silentbob19
Comment Utility
Some how when I submit the first time, all the initial < where missing...

Here it is again... sorry
0
 
LVL 84

Accepted Solution

by:
ozo earned 165 total points
Comment Utility
Scalar found where operator expected at 20324662.perl line 13, near ""<a
        href="$links" (#1)
   
    (S) The Perl lexer knows whether to expect a term or an operator.  If it
    sees what it knows to be a term when it was expecting to see an operator,
    it gives you this warning.  Usually it indicates that an operator or
    delimiter was omitted, such as a semicolon.
   
        (Missing operator before $links?)
syntax error at 20324662.perl line 13, near ""<a href="$links" (#2)
   
    (F) Probably means you had a syntax error.  Common reasons include:
   
        A keyword is misspelled.
        A semicolon is missing.
        A comma is missing.
        An opening or closing parenthesis is missing.
        An opening or closing brace is missing.
        A closing quote is missing.
   
    Often there will be another error message associated with the syntax
    error giving more information.  (Sometimes it helps to turn on -w.)
    The error message itself often tells you where it was in the line when
    it decided to give up.  Sometimes the actual error is several tokens
    before this, because Perl is good at understanding random input.
    Occasionally the line number may be misleading, and once in a blue moon
    the only way to figure out what's triggering the error is to call
    perl -c repeatedly, chopping away half the program each time to see
    if the error went away.  Sort of the cybernetic version of S<20 questions>.
   
String found where operator expected at 20324662.perl line 13, near
        "$links">$text</a>"" (#1)
        (Missing operator before ">$text</a>"?)

Can't find string terminator "END" anywhere before EOF at 20324662.perl line 39 (#3)
   
    (F) Perl strings can stretch over multiple lines.  This message means that
    the closing delimiter was omitted.  Because bracketed quotes count nesting
    levels, the following is missing its final parenthesis:
   
        print q(The character '(' starts a side comment.);
   
    If you're getting this error from a here-document, you may have
    included unseen whitespace before or after your closing tag. A good
    programmer's editor will have a way to help you find these characters.
0
 

Author Comment

by:Silentbob19
Comment Utility
Can you tell me how to upload changed files of a folder.

You got ftp server, password, server root.
And local folder....

Upload only changed files...or the last 5 seconds changed files.
0
 
LVL 8

Expert Comment

by:davorg
Comment Utility
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept ozo's comment as an answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

ozo
EE Cleanup Volunteer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now