[Novalug] Perl "one-liners" - resource found

Paul D. Bain paulbain at pobox.com
Sun Dec 17 12:16:05 EST 2006


      Yesterday, I posted a question (see below) regarding Perl "one 
liners" (OL's).  After a bit of research, I answered my own question, at 
least partially. The best resource for such OL's is apparently Tim 
Maher, whose new book "Minimal Perl" is devoted almost entirely to this 
topic. Chapters from his book have titles such as the following:

Chap. 3 -- Perl as a better grep command
Chap. 4 -- Perl as a better sed command
Chap. 5 -- Perl as a better awk command
Chap. 6 -- Perl as a better find command

See, also, this:

      http://www.consultix-inc.com/consultix/publications/5perlcmds.pdf

You can read more about the book here:

      http://manning.com/maher/
 
http://www.consultix-inc.com/consultix/publications/minimal_perl_book.html

--Paul Bain


Paul D. Bain wrote:
> James Ewing Cottrell 3rd wrote:
>> Joel Fouse wrote:
>>
>>> I, for one, would love to have a little more understanding of awk
>>> (beyond "ps -ef | awk '{print $2}'") and sed (beyond "echo 'foo' | sed
>>> 's/foo/blah/'")
>>>
>>> - Joel
>>>
>> The chief reason for grokking awk is that certain vendor scripts are 
>> written in it.
> 
>> Otherwise, awk is a Dead Language, caught between sh and Perl. You 
>> would be better off learning how to use either of these languages 
>> effectively. For example, the "print the second field" script above 
>> can be expressed as a one-liner in Perl as: ps -ef | perl -lane 'print 
>> $F[1]'
>>
>> and in sh as
>>
>>    ps -ef |
>>    while read one two rest
>>    do
>>        echo $two
>>    done
>>
>> And in fact, while it is possible to write the Tower of Hanoi program 
>> in sed, the same comment applies: learn how to make effective use of 
>> shell scripts, and at the first sign of complexity, leap directly to 
>> perl.
>>
>> Of course, perhaps that advice should be the subject of a tutorial.
> 
> Jim,
> 
>     Thanks for this tip. Could you please point us to a collection of 
> such Perl "one-liners" that replace awk, sed, and the like? I already 
> have the O'Reilly "Perl Cookbook" and several similar Perl books, such 
> as this one:
> 
>     David Cross, "Data munging with Perl" (Manning), ISBN 1-930110-00-6.
> 
> These books include a few one-liners (OL's) and other short scripts, but 
> they tend to focus mostly on longer scripts and do not focus on OL's. Is 
> there a CPAN for such OL's? If not, are there any bloggers who tend to 
> write often about such matters? As you may know, blogger J. Zawodny 
> often writes about MySQL matters -- does he have a counterpart in the 
> world of Perl OL's?
> 
> --Paul Bain



More information about the Novalug mailing list