mkmcconn has asked for the wisdom of the Perl Monks concerning the following question:
Fellow-seekers of Perlish righteousness, lately I have been dabbling with using and and or in places for which I cannot prove precedence among the fathers.
Tell me, am I sinning to use and and or to combine statements as follows?
for my $next (@ARGV){ opendir(PWD,"$next") and my @files = readdir PWD or die "Open \"$_\" failed: $!"; closedir PWD or die $!; print "$_\n" for @files; }
Especially, this seems useful in testing regular expressions as in this recent example, where ...
s/test/whatever/ and print or print;
...will print the substitution if the match succeeds, or print the unmodified string if it fails.
Are there problems with this style? Is it
testing what I think it is? Is it always going to
be reliable, or will it break under some conditions? Is it
more common to do this than I had thought?
mkmcconn
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: and this or that
by jeroenes (Priest) on Feb 05, 2001 at 22:57 UTC | |
by mkmcconn (Chaplain) on Feb 05, 2001 at 23:14 UTC | |
by jeroenes (Priest) on Feb 05, 2001 at 23:37 UTC | |
Re: and this or that
by dws (Chancellor) on Feb 05, 2001 at 23:40 UTC | |
by Fastolfe (Vicar) on Feb 06, 2001 at 01:01 UTC | |
Re: and this or that
by MeowChow (Vicar) on Feb 06, 2001 at 00:33 UTC | |
by dws (Chancellor) on Feb 06, 2001 at 01:41 UTC | |
by MeowChow (Vicar) on Feb 06, 2001 at 01:53 UTC | |
by dws (Chancellor) on Feb 06, 2001 at 02:12 UTC |
Back to
Seekers of Perl Wisdom