Tony Ho wrote:
> 
> Hi guys

Hello,

> I was wondering if you could help me
> 
> I have 2 files.
> One file has 3 data rows, A, B and C
> The file has 1 data row D.
> 
> I need to append row D to rows A and C in the first file, based on some
> condition.
> Any ideas how I could go about this ?
> 
> Another alternative would be for me to open up a new file and write
> row 1 : AD
> row 2 : B
> row 3 : CD
> 
> Is the second approach better in terms of performance than the first
> approach as I will have more than 1 million rows to deal with ?


#!/usr/bin/perl -w
use strict;

open F, 'file two' or die "Cannot open 'file two': $!";
chomp( my $append = <F> );
close F;

{ local ( $^I, @ARGV ) = ( '.bak', 'file one' );
while ( <> ) {
    s/$/$append/ if /some condition/;
    print;
    }
}

__END__


John
-- 
use Perl;
program
fulfillment

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

Reply via email to