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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.