To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.geekOpen lugnet.off-topic.geek in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Geek / 12
11  |  13
Subject: 
Re: awk vs. perl for simple tasks
Newsgroups: 
lugnet.off-topic.geek
Date: 
Thu, 6 May 1999 02:35:11 GMT
Viewed: 
408 times
  
In lugnet.off-topic.geek, jsproat@geocities.com (Sproaticus) writes:
Todd Lehman wrote:
I think perl has a command line option to process STDIN line-by-line in a
simple way (i.e. short number of keystrokes) like awk does

Hmmm...  I *think* a2p handles this by giving the perl script the
"while(<>)" loop.  I don't think perl will do that by itself.

Aha, here it is:  perl -ane


BTW, I think Larry Wall once commented or wrote something to the effect of,
"awk still has to be better than perl at something."

Check perlvar, in the section on $/ (input record separator) -- in Perl, it
can only be a regular string, but in awk, it can be a re.

FS is awk is the field separator, not the record separator.  The record
separator in awk is RS.

Hmm, doesn't look like Perl has an input field separator -- only an output
field separator $, and input/output record separators $/ and $\.

Oh well.  I guess the way to do it is

   ... | perl -ne 'chomp; my @F=split /\t/; print "$F[0]\n"'

and at that point it's probably easier to make some little field-
extraction wrappers.  :)


Personally, I'd undef $/, snarf the entire file, and do a split with an re
on it.  But then, I'm not so familiar with awk.  :-,

That's good if you're snarfing up relatively small files, but what if you're
processing 100 megabytes of STDIN -- say, looking through an httpd log?  And
live tail -f even?  :)

--Todd



Message has 2 Replies:
  Re: awk vs. perl for simple tasks
 
(...) Hmmm, I don't think I'm old enough for that yet. :-D I've just picked up Perl relatively recently. I'd hesitate to do a 100 Mb STDIO pipe on any MS platform. In DOS and Win16/95/98 (which are single-tasking OS's no matter what MS tells you), (...) (26 years ago, 6-May-99, to lugnet.off-topic.geek)
  Re: awk vs. perl for simple tasks
 
(...) It just occurred to me how useful a live tail util would be. How would you implement one in Perl? Would the one at PPT (1) be the one to check out? Cheers, - jsproat 1. (URL) Jeremy H. Sproat <jsproat@geocities.com> (URL) the Force be with (...) (26 years ago, 18-May-99, to lugnet.off-topic.geek)

Message is in Reply To:
  Re: awk vs. perl for simple tasks
 
(...) Hmmm... I *think* a2p handles this by giving the perl script the "while(<>)" loop. I don't think perl will do that by itself. (...) Check perlvar, in the section on $/ (input record separator) -- in Perl, it can only be a regular string, but (...) (26 years ago, 5-May-99, to lugnet.off-topic.geek)

21 Messages in This Thread:








Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR