^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Please note that I prepended this caveat!
Err... this is wrong (though perhaps you just don't know what `grep
-v` does):
I *do* know what -v does. Just missed that switch!
for (grep { -M > 30 and not /\Q_ppsd.zip/ }
as that expr is quite complicated enough to deserve a block of its
own (I find '... and not ...' much less confusing than 'not ... and
Fundamentally I agree. To be more precise, *as far as my personal
tastes are concerned*, I would tend to consider this a *limit* case,
in the sense that the expr is indeed complicated enough that it's not
very nice to have in for (...) but not enough to definitely "deserve"
a separate block.
Surely the print should come before the unlink? Don't put "\n" on the
Surely not "surely". I don't want to print if the unlink() fails. I
agree that there may be a feeble reason for you saying so, based upon
the choice of the message that *may* have better been "`$_' removed".
But then this doesn't really make a big difference and is not an issue
with perl *code*, I'd say!
end of warn and die messages: it suppresses the line number info. Set
$\ rather than put "\n" on the end of every print statement.
I *do* know what "\n" does (with die() and warn()). I use it if I
think it is useful, and I don't use it if I think it is not: simple,
isn't it?
Did you take into account the possibility that the end user of the
program may not be interested in those pieces of info, whereas he
would be content with knowing the file that caused the problem and a
reason why it happened?!?
If you don't want to print if the unlink fails, I would have written
You got it man!
unlink ?
warn "can't unlink '$_': $!" :
print "removed '$_'";
As usual it's a matter of personal taste: believe me, I like the ?:
operator and find it quite useful, especially when I can use its
return value wich is what I need in most cases. Definitely in this
particular case I would have favoured an if then else structure
construct instead.
Ouch! What's that ! there for? Assuming the print will always
succeed, this evaluates as
(unlink and 0) or warn
In fact this is what I want. Pease read more carefully and you'll
discover that...
which means that the warn will always happen. Even without that, it's
^^^^^^
....it will always happen *if* unlink() succeeds. Won't it?
; and it could have done with more friendly formatting:
unlink ? print "removed $_" : warn "can't unlink $_: $!"
for grep { -M > 30 and not /\Q_ppsed.zip/ }
glob "*.downloaded *.kl2_download";
As of my cmts above, I understand your concernings with the pieces of
code I proposed, especially the actual error (i.e. "ignoring -v"), but
to be fair I don't think this particular proposal of yours is in any
way more readable/terse than mine.
I don't like any of the ways you all have written it.
for my $file (glob "*.downloaded *.kl2_download") {
next unless -M $file > 30 and $file !~ /\Q_ppsed.zip/;
unlink $file or do {
warn "Can't unlink '$file': $!";
next;
};
print "Removed '$file'\n";
}
It's a bit more verbose, but easier (at least for me) to read.
I partially agree. Of course I wrote the code in the previous post as
I would have written it if it were to be included in a program of
mine.
In particular I do not have any problem using an explicit variable in
for cycles, but if the body of the cycle is short enough I prefer to
use the implicit one instead. And in this case I would consider it
short enough.
One thing about your proposal that I really do *not* like is the
(IMHO) unnecessary do block. But that is only MHO...
Michele