>>>>> "SB" == Steve Bertrand <[email protected]> writes:
>> I was just thinking, but didn't get a chance to test what would happen
>> if I declared $var = '', and then performed a regex check on it.
SB> This tells me that pre-declaring a var with '' makes my original logic
fail:
that isn't 'predeclaring' but initializing.
SB> % perl -e '$var=""; print 2 if $var !~ /1/; print 1 if $var'
i generally never use !~ but prefer to invert the boolean test. i think
it reads better to say unless $var =~ /1/.
SB> ...so in this case, I'd have to switch my logic backwards, and change my
SB> original regex check:
SB> if ( $month !~ m{ \A \d{4}-\d{2} \z }xms )
SB> to something like this:
SB> if ( $month && $month !~ m{ \A \d{4}-\d{2} \z }xms )
it depends on how you handle the command line arg. a null string will
fail that regex and an arg of '0' will not be checked since the $month
test will fail.
you said you didn't want any stuff on how you handled command line args
i think you do need to address it. it is best to check @ARGV for its
size rather than $ARGV[0] for its truth. then you can tell if a null
string '' or 0 was passed in.
SB> *also*... how can I use 'perl' on the command line, but in a way that I
SB> can use multiple lines in my terminal? I see many code snips for Perl
SB> one-liners that cover multiple lines. Is this a copy/paste/cleanup job?
SB> eg:
SB> % perl -e 'print [ENTER pressed]
SB> Unmatched '.
SB> ...on FreeBSD.
that is a shell issue, not a perl issue. most shells can handle an open
quote with returns inside until you close the quote. bash can do it for
sure.
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/