Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Lo, for i am blind

by jcpunk (Friar)
on May 17, 2003 at 00:59 UTC ( [id://258809]=perlquestion: print w/replies, xml ) Need Help??

jcpunk has asked for the wisdom of the Perl Monks concerning the following question:

i am getting the following error and have no idea why
syntax error at ./vacation.pl line 33, near ") &" syntax error at ./vacation.pl line 38, near "}" Execution of ./vacation.pl aborted due to compilation errors.

there is obviously a simple reason for this error that i just cannot find.....
the code for the script is below
#!/usr/local/bin/perl -w use strict; #declare vars our $set_fwd; our $username; our $message; our $on_off; our $FILENAME; our @list_of_files; #initialize @list_of_files to what the correct list of files @list_of_files=(".forward", ".vacation.msg", ".vacation.pag", ".vacati +on.dir"); `touch Adfasfasfasdfasdfhlasfhasdfhdsfjhjdhsfhfajfhjfhasjfh`; ### # pass arguments in this patern: username on/off message no quotation +s needed ### if (($#ARGV > 1) || (($#ARGV ==1) && ($ARGV[1] eq "off"))) { $username=$ARGV[0]; $on_off=$ARGV[1]; if($on_off eq "on") { $message = join (" ",@ARGV); $message =~ s/$username//; $message =~ s/$on_off//; &On(); } elsif ($on_off eq "off") &Off(); else { print "Necessary Value Contains Incorrect Parameters\n"; exit 1; } } else { print "Error Reading Action\n"; exit 1; } print " <div align=\"center\"> $username\'s vacation message has been + \n"; print " <font color=red>"; if($on_off eq "on") print "Activated"; else print "Deactivated"; print " </font>.</div><BR>\n"; print " <div align=\"center\">\n"; print " </div>\n"; print " <center><BR>Please E-Mail <a href=\"mailto:$username\@iwu +.edu\">$username\@iwu.edu</a>\n"; print " to test this message. <BR> If you "; if($on_off eq "on") print "do not "; print "recieve an automatic response with your\n"; print " vacation message please resubmit this form</center>\n"; } else print "<b>Not all necessary values have been given.</b>\n"; sub On { foreach $FILENAME (@list_of_files) { open(TempFile, ">/home/$username/$FILENAME") || die ("Unable to op +en /home/$username/$FILENAME"); if ( $FILENAME eq ".forward") { #.forward must look like #\username, "|/usr/bin/vacation username" $set_fwd="\\$username, \"|/usr/bin/vacation $username\""; print TempFile $set_fwd; } if ( $FILENAME eq ".vacation.msg") { print TempFile $message; print TempFile "\n"; } close(TempFile); `chmod 644 /home/$username/$FILENAME`; `chown $username /home/$username/$FILENAME`; } } sub Off { foreach $FILENAME (@list_of_files) `rm -f /home/$username/$FILENAME`; }
Can anyone put a second set of eyes on this for me? and possibly offer optimization suggestions......

Replies are listed 'Best First'.
Re: Lo, for i am blind
by pfaut (Priest) on May 17, 2003 at 01:06 UTC

    Perl requires braces around code blocks on if statements.

    elsif ($on_off eq "off") &Off(); else

    should be

    elsif ($on_off eq "off") { &Off(); } else
    90% of every Perl application is already written.
    dragonchild
Re: Lo, for i am blind
by Limbic~Region (Chancellor) on May 17, 2003 at 01:08 UTC
    jcpunk,
    elsif ($on_off eq "off") &Off(); else {
    You are missing the open and close curly brace in the elsif.

    Additionally:

  • You shouldn't use backticks in a void context `` - use system instead
  • It is also considered bad form to call a sub with & and ()

    Cheers - L~R

•Re: Lo, for i am blind
by merlyn (Sage) on May 17, 2003 at 11:44 UTC
    In addition to the other things pointed out already in this thread, I do believe (although I may be wrong: it's early here {grin}) that:
    syntax error near ...
    is a perl 4 error message. Perhaps you should upgrade to something released within the past decade...?

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Well, if he's using perl 4, he's not using it on that code or it would be complaining about all those our declarations.

      90% of every Perl application is already written.
      dragonchild
      it is a perl 5.004 error.... if i could upgrade it i would, but it isnt my server and all i can do is petittion for it, which i have... sigh
Re: Lo, for i am blind
by TVSET (Chaplain) on May 17, 2003 at 07:30 UTC
    Since pfaut and Limbic~Region did already point out the error, I'd like to add two small comments.
    • Ok, perl allows you to not put braces in if..else constructions, if you have only one line in the block. But please, don't do it. It decreases readability of your code. Indent doesn't help too much. And of course, not putting braces, leads to errors like you just had. :)
    • Use CGI module for HTML generation. You code will look much simplier without all those quoting escaping staff.

    Leonid Mamtchenkov aka TVSET

      Eh-eeeeeert! Wrong. C allows if(test) statement else statement;. Perl does not.

        Oops. :) I assume the code from the OP worked:
        if($on_off eq "on") print "Activated"; else print "Deactivated";
        Never used it myself, though. The world is full of wonders :)

        Leonid Mamtchenkov aka TVSET

Lo, for i am blind, addendum
by jcpunk (Friar) on May 17, 2003 at 01:02 UTC
    it also doesnt seem to be touching that file when i run it... blast

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found