Peter Lemus wrote:
> 
> I have a file "1st file) that reads...
> one
> two
> three
> four
> five
> 
> Anotherone "2nd file"that reads:
> day
> weeks
> months
> quarter
> year
> century
> 
> I need to read the 2nd file and add the text from it
> to every word of the first 1st file. So it will look
> something like:
> 
> oneday
> oneweek
> onemonth
> onequarter
> oneyear
> onecentury
> twoday
> twoweek etc..etc.
> 
> Pleas give me an example on how I can accomplish this.


Here is one way to do it:

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

open FILE, 'file1.txt' or die "Cannot open 'file1.txt': $!";
chomp( my @data1 = <FILE> );
close FILE;

open FILE, 'file2.txt' or die "Cannot open 'file2.txt': $!";
my $data2 = do { local $/; <FILE> };
close FILE;

my $regex = join( '|', sort { length $b <=> length $a } split( ' ', $data2 ) );

open FILE, '> file2.txt' or die "Cannot open 'file2.txt': $!";
for ( @data1 ) {
    $data2 =~ s/^(.*)($regex)$/$_$2/mg;
    print FILE $data2;
    }

__END__



John
-- 
use Perl;
program
fulfillment

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

Reply via email to