Download Perl One-Liners: 130 Programs That Get Things Done by Peteris Krumins PDF

By Peteris Krumins

A part of the thrill of programming in Perl lies in tackling tedious initiatives with brief, effective, and reusable code. usually, the right instrument is the one-liner, a small yet robust software that matches in a single line of code and does something quite well.

In Perl One-Liners, writer and impatient hacker Peteris Krumins takes you thru greater than a hundred compelling one-liners that do every kind of convenient issues, comparable to manage line spacing, tally column values in a desk, and get an inventory of clients on a approach. This cookbook of helpful, customizable, and enjoyable scripts may even aid hone your Perl coding talents, as Krumins dissects the code to provide you a deeper figuring out of the language.

You'll locate one-liners that:
- Encode, decode, and convert strings
- Generate random passwords
- Calculate sums, factorials, and the mathematical constants π and e
- upload or eliminate spaces
- quantity strains in a file
- Print strains that fit a particular pattern
- fee to work out if a bunch is key with a standard expression
- Convert IP handle to decimal form
- exchange one string with another

And many extra! keep time and sharpen you coding talents as you discover ways to triumph over these pesky projects in a couple of accurately put keystrokes with Perl One-Liners.

Show description

Read or Download Perl One-Liners: 130 Programs That Get Things Done PDF

Similar technology books

Humans 3.0: The Upgrading of the Species

Existence for early people wasn't effortless. they might were in a position to stroll on ft and create instruments four million years in the past, yet they couldn't keep in mind or speak. thankfully, humans received smarter, and issues acquired greater. They remembered on-the-spot ideas and shared the dear info in their reviews.

Central American Wars 1959 - 89

Considering that Fidel Castro's victory in Cuba in January 1959 the us have been involved that any swap of presidency in a vital American nation aren't herald an identical Soviet-backed communist regime; and to avoid this it has built a variety of responses, from direct army intervention, via aid of neighborhood armies, to diplomatic isolation and fiscal blockade.

Crash course in electronics technology

Mixed with the 2 different Crash direction books, electronic expertise and Microprocessor know-how, this ebook kinds a whole direction in electronics and microcomputer expertise applicable for technical faculties, commercial education, and hobbyists. Crash direction in Electronics know-how teaches the fundamentals of electronics, parts, and circuits in an easy-to-understand layout.

Extra info for Perl One-Liners: 130 Programs That Get Things Done

Example text

6, except you replace min with max. 9 Replace each field with its absolute value perl -alne 'print "@{[map { abs } @F]}"' This one-liner first auto-splits the line using the -a option. The split fields end up in the @F variable. Next, it calls the absolute value function abs on each field with the help of the map function. Essentially, the map function applies a given function to each element of the list and returns a new list that contains the results of applying the function. For example, if the list @F is (-4, 2, 0), mapping abs over it produces the list (4, 2, 0).

3, except it only numbers and prints lines that match /regex/. It doesn’t print nonmatching lines. 5: record foo bar baz record qux And let’s say you want to number and print only the lines that contain the word record. 7 Number all lines but print line numbers only for lines that match a pattern perl -pe '$_ = "$. 6. Here, the line number is prepended to the line if the line matches a /regex/; otherwise, it’s simply printed without a line number. , $_' This one-liner uses printf to print the line number together with the line contents.

In this loop, each line is read by the diamond operator <> and is placed in the special variable $_, but it’s not printed! You have to print the line yourself—a useful feature if you want to print, modify, or delete lines selectively. In this one-liner, the code is print unless /^$/, so the entire Perl program becomes while (<>) { print unless /^$/ } Unraveling this a bit further, you get this: while (<>) { print $_ unless $_ =~ /^$/ } This one-liner prints all nonblank lines. ) This one-liner also removes all blank lines: perl -lne 'print if length' This one-liner uses the -l command-line argument, which automat­ ically chomps the input line (basically removes the newline at the end) and appends it back at the end of the line when printing.

Download PDF sample

Rated 4.95 of 5 – based on 43 votes