Perl invocation options

I have known about perl invocation options for a while, and I have used them on several occasions. However, I’m not sure I understood just how far the rabbit hole goes.

Try the following:

perl -wnle 'print "Each line of the file is printed here $_";' foo #Process through each line.
perl -wpie 's/replace/with/g;' foo # sed -i replacement
perl -wnlae 'print $F[0]' foo # awk '{print $1}' replacement

The best part is that these go beyond just replacing existing shell commands because of all the powerful constructs that exist in perl. If you are interested in more of the same, check out the linked book. Now if you will excuse me I am going to go follow the white rabbit…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s