ggadd has asked for the wisdom of the Perl Monks concerning the following question:
I was trying to extract month and day from localtime() for use in a larger program using if statements. The numerical day worked fine, but the month string seemed to disappear. There's probably a simple explanation my newbie mind isn't grasping. Testing this out below(March 9):
use warnings; $time = scalar localtime(); $time =~ /(\s[A-Z][a-z]+)/; $month = $1; $time =~ /\s(\d+)\s/; $day = $1; print $month," ",$day; print "\n"; if($month eq 'Mar'){print "true\n";} else{print "false\n";} if($day == 9){print"true";} else{print"false";} #prints: Mar 9 false true
The $month value('Mar'} seems to vanish within the if statement and only in the if statement. What's going on here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: value disappears in if statement
by Anonymous Monk on Mar 10, 2015 at 03:30 UTC | |
by Anonymous Monk on Mar 10, 2015 at 03:39 UTC | |
by trippledubs (Deacon) on Mar 10, 2015 at 04:34 UTC | |
by Anonymous Monk on Mar 10, 2015 at 07:57 UTC | |
by Anonymous Monk on Mar 10, 2015 at 13:08 UTC | |
by ggadd (Acolyte) on Mar 10, 2015 at 22:49 UTC | |
|
Re: value disappears in if statement
by trippledubs (Deacon) on Mar 10, 2015 at 05:05 UTC | |
by sandy105 (Scribe) on Mar 10, 2015 at 08:17 UTC | |
|
Re: value disappears in if statement
by Anonymous Monk on Mar 10, 2015 at 03:36 UTC | |
|
Re: value disappears in if statement
by ww (Archbishop) on Mar 10, 2015 at 14:32 UTC | |
|
Re: value disappears in if statement
by CountZero (Bishop) on Mar 10, 2015 at 20:32 UTC |