Announcing my third e-book "Perl One-Liners Explained" - good coders code, great reuse |
Announcing my third e-book "Perl One-Liners Explained" Posted: 01 Feb 2012 05:33 AM PST Hello ladies and gentlemen! I'm happy to announce my 3rd e-book called "Perl One-Liners Explained." This book is based on the "Famous Perl One-Liners Explained" article series that I wrote over the last 3 years and that has been read over 500,000 times! I went through all the one-liners in the article series, improved explanations, fixed mistakes and typos, added a bunch of new one-liners, added an introduction to Perl one-liners and a new chapter on Perl's special variables. Table of ContentsThe e-book has 111 pages and it explains 130 unique one-liners. Many of one-liners are presented in several different ways so the total number of one-liners in the book is over 200. The e-book is divided into the following chapters:
What are Perl One-Liners?Perl one-liners are small and awesome Perl programs that fit in a single line of code and they do one thing really well. These things include changing line spacing, numbering lines, doing calculations, converting and substituting text, deleting and printing certain lines, parsing logs, editing files in-place, doing statistics, carrying out system administration tasks, updating a bunch of files at once, and many more. Perl one-liners will make you the shell warrior. You'll be able to do all these tasks in seconds. No kidding! Let's take a look at several practical examples that you can easily do with one-liners. All these examples and many more are explained in the e-book. I have also made the first chapter of the book, Introduction to Perl One-Liners, freely available. Please download the e-book preview to read it. Example 1: Replace a string in multiple files at once perl -p -i.bak -e 's/Config/config/g' conf1 conf2 conf3 Suppose you have 3 configuration files, and you discover that you made a mistake and need to replace all occurrences of I explain the Example 2: Generate a random 8 character password perl -le 'print map { ("a".."z")[rand 26] } 1..8' This one-liner generates and prints a random 8 character password. It uses the list range operator Example 3: URL-escape a string perl -MURI::Escape -lne 'print uri_escape($string)' Here we use the You can install this module from CPAN by running I have this one-liner as an alias actually for both URL-escaping and unescaping URL-escaping as it's such a common thing to do: urlescape () { perl -MURI::Escape -lne 'print uri_escape($_)' <<< "$1" } urlunescape () { perl -MURI::Escape -lne 'print uri_unescape($_)' <<< "$1"; } Then I can do this in the shell: $ urlescape "http://www.catonmat.net" http%3A%2F%2Fwww.catonmat.net $ urlunescape http%3A%2F%2Fwww.catonmat.net http://www.catonmat.net Very useful! Example 4: Print all lines from line 17 to line 30 perl -ne 'print if 17..30' Here we use the binary flip-flop operator Example 5: Remove all consecutive blank lines, leaving just one perl -00pe0 I included this one-liner here in the examples just to show you how funny and obscure one-liners can get. This one-liner deletes all repeated blank lines from the input or from the given file. It does it by enabling the paragraph slurp mode through I explain this one-liner in more details in the e-book. As I hope you can see, knowing how to write one-liners is very useful. It was one of my top priority tasks through the years to become very efficient in the shell. Literally every day when I'm programming, I have to do all kinds of data processing tasks, changing files, verifying output, doing quick calculations, parsing data, etc, and knowing Perl one-liners makes it really fast to get things done. Now that I have written this e-book, you can become very efficient, too. Enjoy! Book PreviewI prepared a free book preview that contains the first 13 pages of the book. It includes the table of contents, preface, introduction to Perl one-liners and the first page of the second chapter. Buy it now!The price of the e-book is $9.95 and it can be purchased via PayPal: After you have made the payment, my automated e-book processing system will send you the PDF e-book in a few minutes! Tweet about my book!Help me spread the word about my new book! I prepared a special link that you can use to tweet about it: What's next?I really love writing about programming and I have planned writing many more books. 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. Enjoy!Enjoy the book and don't forget to leave comments about it! Ask me anything you wish and I'll help you out. Also if you're interested, take a look at my other two e-books. The 1st one is called "Awk One-Liners Explained" and the 2nd one is called "Sed One-Liners Explained" They're written in a similar style as this e-book and they teach practical Awk and Sed through many examples. Finally, if you enjoy my writing, you can subscribe to my blog, follow me on Twitter or Google+. |
You are subscribed to email updates from good coders code, great reuse To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment
Keep a civil tongue.