Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Syntax error? I don't think so...

by ninja-joe (Monk)
on Apr 27, 2002 at 16:40 UTC ( [id://162525]=perlquestion: print w/replies, xml ) Need Help??

ninja-joe has asked for the wisdom of the Perl Monks concerning the following question:

I swear to god and all that's holy that there are no syntax errors in this script, yet Perl is flagging them. The errors are as follows syntax error at spill.cgi line 25, near ") {" syntax error at spill.cgi line 33, near "}" I've even tried just doing
if(1) { print "hi"; }
and it still flags an error. Does this have to do with the print <<END_HTML statements in my code? Or is it a possible problem with my perl installation or something? Here's the code (spill.cgi):
#!/usr/bin/perl use CGI qw/:standard/; import_names('f'); print header(); use AnyDBM_File; use Fcntl; print <<END_HTML <html> <head> <title>DB Spiller</title> </head> <body> <form method="get" action="spill.cgi"> DB Filename: <input name="data" type="text" size=10><br> <input type="submit" value="Dumb DB Contents"> <input name="action" type="hidden" value="spill"> </form> END_HTML if(defined($f::action)) { tie %db, "AnyDBM_File", "$f::data", O_RDWR, 0644; foreach $key (keys(%db)) { print "$key => $db{$key}<br>"; } } print <<END_HTML </body> </html> END_HTML

Replies are listed 'Best First'.
Re: Syntax error? I don't think so...
by BeernuT (Pilgrim) on Apr 27, 2002 at 16:54 UTC
    There is an error in your
    print <<END_HTML
    try this instead
    print <<END_HTML; blah blah... blah..... END_HTML
    your missing a ";" on the print statement and remember that END_HTML has to be left aligned (on the left margin).

    -bn
      Awesome! I can't believe I didn't try a freaking semicolon... Oh well. Thanks a lot!
Re: Syntax error? I don't think so...
by George_Sherston (Vicar) on Apr 27, 2002 at 18:22 UTC
    You'd have avoided the occasion for that error, and saved some coding time, by using all those lovely CGI functions:
    print start_html('DB SPiller'), startform, 'DB Filename: ', textfield( -name => 'data', -size => 10, ), br, submit('Dumb DB Contents'), hidden ( -name => 'action', -value => 'spill', ), endform;
    and
    print end_html;


    § George Sherston

      George_Sherston is absolutely right, I would say take it one step further. Check out Mason, HTML::Template or Template Toolkit.

      These allow you to remove your markup and design from your code and stick them into a template.

      This provides you with some distinct advantages:

      You avoid mistakes like the one you ran into

      You gain many of the advantages of frames (factoring out repeated elements in your markup) with out the problems associated with frames (i.e. javascript across secure frames, SSL lock not showing if just the inner frame is SSL)

      It is more maintainable and easier to read. Do not take this lightly. I have had the unfortunate responsiblilty of maintaining code that had HTML and SQL in HEREDOCS. Trying to read through code with bad indentation because of HEREDOCS will make your head spin. Imagine if you will buried in 60-70 line of HTML 3 lines that loop are your logic for displaing a table :(


      I personally lean towards Template Toolkit because of the fact it can template more than HTML, but all of them are fine choices



      grep
      Unix - where you can thrown the manual on the keyboard and get a command
        I would have used that HTML::Template module if my script didn't have to hang out on Hostway's servers. Their unix shell account doesn't have the HTML::Template module installed. :-(
Re: Syntax error? I don't think so...
by gav^ (Curate) on Apr 27, 2002 at 22:51 UTC
    You might want to consider the implications of:
    • Just accepting any filename the user gives you
    • Not finding out if you've managed to tie the db successfully

    gav^

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://162525]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-23 23:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found