in reply to Another Q about piping Perl
The idiom to execute perl statements on and print the result of each line of a file is
perl -pe 'perl_statements' < file
or
some_command | perl -pe 'perl_statements'
perl -pe 'perl_statements' < file
or
some_command | perl -pe 'perl_statements'
each line is stored in $_ on which perl_statements act.
Here you want to print all the files in the $HOME/Mail
directory. An all perl solution is:
map{ -f $_ and print "$_ " } <$ENV{HOME}/MAIL/*>
Some people consider using map on empty context is bad form. I don't.
They would propose instead:
for(<$ENV{HOME}/MAIL/*>) { -f $_ and print "$_ " }
or
-f $_ and print "$_ " for <$ENV{HOME}/MAIL/*>
TMTOWTDI
-- stefp
|
---|
Replies are listed 'Best First'. | |
---|---|
(Ovid) Re(2): Another Q about piping Perl
by Ovid (Cardinal) on Oct 12, 2001 at 03:39 UTC | |
Re: Re: Another Q about piping Perl
by blakem (Monsignor) on Oct 12, 2001 at 03:25 UTC |
In Section
Seekers of Perl Wisdom