Perl Information Center Tutorials - One Liners
These tutorials were written to help you get a quick, but thorough, understanding of Perl -
the scope of the language as well as it's specific capabilities.
| Beginners
| Built-In Functions
| Advanced
| CGI Applications
|
|
|
|
|
|
One Liners
Perl allows a complete, single line script to be run from the command line.
These 'one liners' can be a quick way of making changes, finding information
or presenting file content.
Most Perl programmers don't use one liners and are happy to use more
relaxed, readable code in standard multi-line script files. Other programmers
enjoy the speed and convenience of one liners or simply enjoy the challenge
of cramming as much code/logic into one line as possible.
The following three sections provide information on how to create one liners,
over 75 scripts, and detailed explanation of how the scripts work.
The other sections will provide much greater detail but here are two
one liners to get your started. The first is very simple, a standard
Hello World! script. Simply type this in at the command line to see the result.
The second is a bit more complicated, but does a find and replace of text
in several files (in this example, replacing 'cat' with 'dog').
perl -e " print 'Hello World!' "
perl -i.bak -pe "s/cat/dog/g" input1.txt input2.txt input3.txt
That's it - complete Perl scripts on a single line of text!
If you have any suggestions or corrections, please let me know.
|