in reply to Short or Long Hand
Why not just use a simple regex:
print $day, $/ if $day !~ /^0|6$/;
Add:
I made a common beginner mistake and I feel really ashamed about it.
Although above code will work on a single digit as it was demanded
( $day representing a weekday field from localtime() )
it is not logic as it says: don't match 0 at the beginning or don't match 6 at the end.
With nonmatching parens ( !~ /^(?:0|6)$/ ) it will satisfy the logic, still matching nondigits though. So it would've even been better written as !~ /0|6/ since the expected data is a single digit.
I'm so sorry!
print $day, $/ if $day !~ /^0|6$/;
Add:
I made a common beginner mistake and I feel really ashamed about it.
Although above code will work on a single digit as it was demanded
( $day representing a weekday field from localtime() )
it is not logic as it says: don't match 0 at the beginning or don't match 6 at the end.
With nonmatching parens ( !~ /^(?:0|6)$/ ) it will satisfy the logic, still matching nondigits though. So it would've even been better written as !~ /0|6/ since the expected data is a single digit.
I'm so sorry!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Short or Long Hand
by davorg (Chancellor) on Aug 12, 2004 at 15:33 UTC | |
Re^2: Short or Long Hand
by Eimi Metamorphoumai (Deacon) on Aug 12, 2004 at 15:30 UTC | |
by Dietz (Curate) on Aug 12, 2004 at 15:37 UTC | |
Re^2: Short or Long Hand
by Scarborough (Hermit) on Aug 12, 2004 at 15:28 UTC |
In Section
Seekers of Perl Wisdom