http://qs321.pair.com?node_id=118370


in reply to Re: Another Q about piping Perl
in thread Another Q about piping Perl

stefp wrote:

Some people consider using map on empty context is bad form. I don't.

I think it depends on the context. If you're doing a short one-liner like that, it's not a big deal. In fact, if you're just writing a small "throw away" script that only gets used once or twice and you don't care about performance or memory, then it's not a big deal IMHO. However, if you're writing large applications, it pays to be rigorous. Creating a bunch of only to throw away the return value is a waste of resources and a for loop is preferable. Doing what you did to print all the files in the $HOME/MAIL/ directory:

# print all files in the directory (an overblown and limited 'ls' +or 'dir' perl -e '-f $_ and print "$_ " for glob(shift)' ./*

Side note: since I tested that on a Windows box and it doesn't like single quotes on the command line and I hate using \" all the time to embed quotes, I wrote this:

perl -e "-f $_ and print $_.$,.$/ for glob(shift)" ./*

No wonder people say Perl has too much punctuation :)

Cheers,
Ovid

Update: Hmm... seems I wasn't paying attention to blakem's post.

Vote for paco!

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.