4 Feb Peteris Krumins has a new book, Perl One-Liners Explained. His new book is in the same style as his previous books on awk and sed. the gnarly Perl one-liner for accomplishing short tasks that do not need a complete The -e switch allows me to write Perl scripts directly on the command line. Perl One-liners. Perl one-liners are small and awesome Perl programs that fit in a . I explain this example in detail in one-liner (page 41), but basically you.

Author: Kim JoJole
Country: Madagascar
Language: English (Spanish)
Genre: Career
Published (Last): 7 June 2007
Pages: 445
PDF File Size: 13.27 Mb
ePub File Size: 13.69 Mb
ISBN: 228-6-25079-313-5
Downloads: 82610
Price: Free* [*Free Regsitration Required]
Uploader: Tugami

It uses the list range operator. For me, one part laziness and one-oiners part flexibility, and the flexibility part I might be rationalizing. Configure these properly before diving into any Perl problem. The paragraphs file contains the -0 documentation from perlrunused in the following example:. Sigh; I am not making much of a show of my Perl knowledge today.

Useful Perl one-liners () | Hacker News

Thanks for this article series. Now I know the -e needs nothing but a constant here. To split output among multiple files, change where standard output points at based on some test. Operator precedence may require the use of unless instead of if! Hi Stuart, I’ve been busy so forgive me my late reply. Some examples are double spacing a file, numbering the lines, doing various text substitutions, etc.

Never use the -ie ‘? It is one of my top technical books, not just for density of actionable information, but also for the pure general excellence.

The perl program runs on every line making the edit. Thank you so much! Combining the flip-flop operator with print if makes it print only lines The next few are going to be a book on mastering vim, a practical guide on how to be anonymous on the web, and the catonmat book.


GNU sed does not have that limit: If so you can do the following: The unless statement is equivalent to if notbut is different from if! So with Perl, you can do it everywhere. Be faster than Larry Wall in the shell! Subscribe through an RSS feed: And I actually think Perl is correct here and you should only need to escape those onw-liners if you want literal matchesbut I have a weird environment Cygwin and it’s possible the sed build there is a little messed up.

: Perl One Liners

If you feel unproductive or uncomfortable with Perl, you should avoid it and use whatever language strikes your fancy. But didn’t know of xkill, thanks. I included this one-liner here in the examples just to show you how funny and obscure one-liners can get.

Ali, could have bought two – one for me and one for you! Here are several others that do the same:. Find is hardened against that kinda shenanigans. If a recursive replace is needed, either investigate the use of the modules File:: Version control also offers diff support to sanity check the changes made, and commits to log reasons with changes.

Peter Krumins’ blog about programming, hacking, software reuse, software ideas, computer security, browserling, google and technology. Also, never use killall. Now that I finished the trilogy of awk, sed, and perl e-books, I will finally finish the parser to convert them to. Sometimes I want to send a private message, or just thank for the great comment. They have received more thanviews total and they attract a few thousand new visitors every week.


This may not be the ideal form for commonly used commands.

All the other newlines get ignored. That said, variations on my one are also handy for doing any further processing on the lines – eg, I do stuff like this pretty regularly: Avoid killall; that’s unportable is a special way. How would I create a one liner to print all lines in a text file that DON’T contain the word “water” unless the line also contains the word “plants”? No need to type out a convoluted command. I haven’t checked every technical detail, I’ll trust you to get that right.

The e-book has pages and it explains unique one-liners.

Perl One Liners

Please download the e-book preview to read it. Sadly there oe-liners situations when a hanging Firefox doesn’t have a window to place the xkill skull-and-crossbones cursor if death on. Perls regex parser is still far above the features in more modern languages, supporting, among other things, code execution within capture groups.

Anno icke on freenode perl Permalink. I use a command line program in Win 7 called getmail, which downloads emails from one of my accounts and saves them as. Some of those topics are basic UNIX programming things signals, per, process state, controlling tty. I hope it becomes as as awk1line. The one-liners will make heavy use of Perl special variables.

MichaelMoser on Nov 30, I will never ever spam you.