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]