Perl is great at parsing the output of various programs. This is a task for which many people use tools such as awk and sed. Perl gives you a larger vocabulary for performing these tasks. The following example is very simple, but illustrates how you might use Perl to chop up some output and do something with it. In the example, Perl is used to list only those files that are larger than 10KB:
$ ls -la | perl -nae 'print "$F is $F\n" if $F > 10000;'
The -n switch indicates that I want the Perl code run for each line of the output. The -a switch automatically splits the output into the @f array. The -e switch indicates that the Perl code is going to follow on the command line.
Was this article helpful?