Maxim, I have set "use strict;". Below is a script to test the sub. As is the script should simply print "the script didnt work". If you change the last line of the following test script to: error_notify(q,"the script didnt work"); It fails with this message: Can't find string terminator "," anywhere before EOF at test2 line 77.
If you change the "q" (when calling the sub) to any other letter it does what it is supposed to. #!/usr/bin/perl use strict; my $MAIL_LIST = "[EMAIL PROTECTED]"; my $PAGE_LIST = "[EMAIL PROTECTED]"; my $PROC_NAME = "err test"; my $HOST_NAME = "mybox"; my $STEP_NAME = "Test Error Notify"; sub error_notify { my $ERR_USAGE = "error_notify (e,p,x, \"Message Text\")\n"; my $ERR_DATE_TIME = `date`; chomp ($ERR_DATE_TIME); my $DEFAULT_MESSAGE = "Undefined Error!"; my (@ERR_OPTS, $MESSAGE); foreach (@_) { if (/^e$/) { push @ERR_OPTS, "email"; } elsif (/^p$/) { push @ERR_OPTS, "page"; } elsif (/^x$/) { push @ERR_OPTS, "exit"; } elsif (/^\w$/) { print "Invalid error_notify Option\n$ERR_USAGE"; } else { $MESSAGE = $_; } } unless (defined $MESSAGE) { $MESSAGE = $DEFAULT_MESSAGE }; print "\n\nError: $MESSAGE\n\n"; foreach (@ERR_OPTS) { if ( /^email$/ ) { if ( defined $MAIL_LIST ) { open MAIL, "| mail -s \"$HOST_NAME $PROC_NAME Script Error\" $MAIL_LIST" or warn "Unable to open mail.\n"; #------------------------------------------ print MAIL << " EOM"; Host Name : $HOST_NAME Proc Title : $PROC_NAME Script Name: $0 Date / Time: $ERR_DATE_TIME Step Name : $STEP_NAME Err Message: $MESSAGE User ID : $> Proc Number: $$ EOM #------------------------------------------ close (MAIL); print "Sending Mail To:\n$MAIL_LIST\n\n"; } else { print "No mailing list defined.\nNo mail sent.\n"; } } elsif ( /^page$/ ) { if ( defined $PAGE_LIST ) { open PAGE, "| mail -s \"$HOST_NAME $PROC_NAME Error\" $PAGE_LIST" or warn "Unable to open mail.\n"; #------------------------------------------ print PAGE << " EOP"; $ERR_DATE_TIME EOP #------------------------------------------ close (PAGE); print "Sending Page To:\n$PAGE_LIST\n\n"; } else { print "No paging list defined.\nNo page sent.\n"; } } elsif ( /^exit$/ ) { print "exit\n"; exit 1; } } } error_notify("the script didnt work"); # End of Script --- Maxim Berlin <[EMAIL PROTECTED]> wrote: > Hello Michael, > > Wednesday, December 05, 2001, Michael McQuarrie <[EMAIL PROTECTED]> wrote: > > > MM> I am defining a sub that takes only specific options: > > MM> sub error_notify > MM> { > MM> my $ERR_USAGE = "error_notify (e,p,x, \"Message Text\")\n"; > > MM> foreach (@_) > MM> { > MM> if (/^e$/) { push @ERR_OPTS, "email"; } > MM> elsif (/^p$/) { push @ERR_OPTS, "page"; } > MM> elsif (/^x$/) { push @ERR_OPTS, "exit"; } > MM> elsif (/^\w$/) { print "Invalid error_notify Option\n$ERR_USAGE"; } > MM> else { $MESSAGE = $_; } > MM> } > MM> bla bla bla... > > MM> This sub is supposed to be called like this: > MM> error_notify(e,p,x,"This is the error message that will be sent out"); > bad syntax. you should use ' or " for character variables. > 'e','p','x' > > MM> The problem that I am running into is that whenever "q" (which > MM> isn't a valid option) is supplied as an argument to the sub like > MM> this: > MM> error_notify(q,"Whatever"); > normally, you can not use this syntax. you should get > "Can't find string terminator "," anywhere before EOF" > error from perl. use > error_notify("q","Whatever"); > MM> I get an error because the "q" is interpreted as a quote operator. > MM> I am using a \w to try and match all invalid options but \w will > MM> not match the q. Anyone know a way around this? I would like to > MM> keep the same syntax for calling the sub. > i suggest you to put > use strict; > line at the top of your source and run > perl -c yoursource > to check syntax. > > Best wishes, > Maxim mailto:[EMAIL PROTECTED] > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __________________________________________________ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]