[ale] Perl Question

Fletch fletch at phydeaux.org
Mon Oct 16 15:14:42 EDT 2000


>>>>> "Danny" == Danny Cox <danny at compgen.com> writes:

    Danny> Ken, On Mon, 16 Oct 2000, Danny Cox wrote:
    >> > I have a little perl problem, lets say I have a grep and it
    >> returns true.  > I want to not only print that line but I wanna
    >> print the line > below. Anyone know how I noght do this?
    >> 
    >> See the '-A' option to grep (at least, GNU grep).
    >> 
    >> grep -A1 'pattern' file
    >> 
    >> will do what you wish.

    Danny> 	Whups!  I missed the 'perl' part.  Well, you could use
    Danny> the system() function in the same way.

    
        Suguestions to use system to call grep from perl are almost as 
bad as using cat to pipe files to grep on the command line. :)


while( <> ) {
  if( /somepattern/ ) {
    my $nextline = <>;
    print $_, $nextline;
  }
}


        If you also want to check the next line for the pattern, then
stick a `redo' after the print.

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
678 443-6239(w)       |  scary questions." -- Jules                =(___)=
                      |                                               U
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list