[EMAIL PROTECTED] wrote:
> Hello,
> 
>   I want to open a text file, look for a specific string, replace it
> with a new string, and write the line out to another file. For lines
> not containing the specific string, I want to write out as is.
> 
> I was wondering if it is possible to do it with a map or splice or
> grep command rather than a foreach loop.
> 
        The real question is how large a file are you going to work with? If in 
millions or less, then could read into variable, chg and writeout to new file. 
if in gigabytes, then what you are doing is fine. 

        Why go through $infile and not just do while ( <INFILE> ).  Now you can 
go against $_ . Though you are chomp then write without the return?

Wags ;)
> Perhaps, I should be looking at some executable that replaces one
> string with another within a file?
> 
> I have resorted to a foreach loop.
> 
> Here is a snippet of my code:
> 
>            $currnodename = "AMACHINE";
>            $oldnodename = "BMACHINE";
>            $infile = "$ENV{FT}\\qld\\$msg.qli";
>            $outfile = $ENV{TEMP} . "\\$task.tmp";
> 
>            open (INFILE, "<$infile") || die "Can not open $infile";
>            open (OUTFILE, "+>$outfile") || die "Unable to open
>            $outfile"; while ($inline = <INFILE>)
>               {
>                chomp $inline;
>                $inline =~ s/$oldnodename/$currnodename/g;
>                print OUTFILE $inline;
>               }
>            close INFILE;
>            close OUTFILE;
> 
> 
> Thank you
> 
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to