Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: new to perl

by brx (Pilgrim)
on Jul 13, 2012 at 14:09 UTC ( [id://981627]=note: print w/replies, xml ) Need Help??


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

    Oneliner - didn't work, i already had a pipe in my command and i didn't bother to find out why.
    The deparsed command was great, worked like a charm - Thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://981627]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found