in reply to new to perl
Quick and dirty answer:
ls -l *.TMP | perl -anle 'print "Mypath\\MyPerl_2.pl $F[-1]"'You can replace 'print' by system to execute commands. Caveat: if a filename contains a whitespace, this oneliner is wrong.
Here, the real code executed (oneliners are not easy for beginners):
$ perl -MO=Deparse -anle 'print "Mypath\\MyPerl_2.pl $F[-1]"' BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; our(@F) = split(' ', $_, 0); print "Mypath\\MyPerl_2.pl $F[-1]"; }
As you can see, it use split.
You could want to use open to open a file.
http://perldoc.perl.org/perlop.html#I%2fO-Operators to understand while ( ... = <>)
And see how regex works in perlretut...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: new to perl
by kroz (Initiate) on Jul 16, 2012 at 06:02 UTC |