A witty retort or A line which by itself is funny. Commonly used in action films. Some great examples can be found in Independance Day and Die Hard, as well as Army of Darkness. A prequisite of being an action hero is to be able to come up with pithy one-liners.

A programming solution accomplished in one line of code. Usually written in perl, one liners are often used to express the elegance of a programming language. Perl hackers often claim to be able to equate any C program to one line of perl; however, this may just be an example of hubris.

If you are an adept of the Perl programming language, you will often find yourself typing one-liners to solve common system administration tasks, the kind you'd solve with sed or grep. Perl offers in fact a special mode of invocation with the switch -e where it gets passed a whole program on the command line, like in this case:
perl -e "print grep /^h/i, glob('*.txt');"
That prints the names of all the text files in the current directory starting with the letter h (something like dir h*.txt, but this is just a silly example - you can use the raw power of regular expressions to code complex matching rules).

What most people don't know is that you can actually repeat the -e switch more than once, so that you can actually build programs of more than one line using the one-liner syntax like in this case:

perl -e "print grep /^h/i, glob('*.txt');" \
     -e "print 'Hello, world\n;"
This way you can be sure you'll never be out of space for your one-liners.

A different option that's often used for one-liners is the auto-loop option -n, that reads from STDIN or the passed filename and loops on each input row. This way you can build simple one liners like the following

perl -n -e "print lc;" x.txt
Where all of the lines of x.txt will be printed in lowercase to STDOUT.

But the true Swiss-Army Chainsaw nature of Perl only shows when you add the -M (module) switch, where you can import any module available to your Perl and use it. This program, for instance, downloads and prints the Everything2 home page using the LWP::Simple web access module:

perl -MLWP::Simple -e 'print get("http://www.everything2.com";)'
That's not bad for one line of code.

Log in or registerto write something here or to contact authors.