in reply to Use of grep and foreach

How about using map.
use strict; open(INFILE, "/path/to/file"); my @lines = map {s/oldthing/newthing/ if(m/myLine/);$_;} <INFILE>; close(INFILE); open(OUTFILE, ">/path/to/file"); print OUTFILE $_ foreach(@lines); close(OUTFILE);

UPDATE: Changed print to filehandle(OUTFILE) instead of STDOUT

Replies are listed 'Best First'.
Re: Re: Use of grep and foreach
by monaLisa (Initiate) on Aug 11, 2003 at 13:34 UTC
    I am using this, but does not do want I want:
    if(/^otsort/) { $myLine =~ s|(/apost.*) f\(fix,(\d{4}\).*$|"$1,record\($2\)"|g; print "$myLine\n"; print outFile "$endUnixLine\n"; }