> -----Original Message-----
> From: Frank Newland [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 09, 2001 12:35 PM
> To: [EMAIL PROTECTED]
> Subject: Perl equivalent to awk's 'getline'
> 
> 
> Readers:
> awk has a function  called 'getline' which reads the next 
> line of input
> without changing control of the script.
> 
> My input file contains pairs of records. When I find a record 
> that matches
> my search pattern, I want that record and the next record. 
> In awk, I used the 'getline' which did just that.
> 
> How can I do this in perl?
> Does using the $* variable get me there?
> --------------------------------------------------
> #!/usr/bin/perl -w
> use strict ;
> ## If the record ends in 03 then capture this record and the next one.
> while (<>) {
> chomp ;
> 
> if ( /03$/)  {
> print ; #print this record, now how do I capture just the next record?
> }

In addition to the responses you've already received, you can also
look at the a2p utility that comes with perl. It translates awk scripts
into perl scripts.

It translates awk's getline into:

    if ($getline_ok = (($_ = <>) ne '')) {
        chomp;  # strip record separator
    }

Which seems overly cumbersome to me. I would think using

   chomp($_ = <>);

would be just as good.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to