Curtis Poe wrote:
>
> --- "John W. Krahn" <[EMAIL PROTECTED]> wrote:
> > 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.
> >
> > [snip]
>
> That's an interesting solution, but I think the following is a bit cleaner (unless I
>am just
> completely missing something here).
>
> #!/usr/bin/perl -w
> use strict;
>
> open FIRST, "< first.txt" or die "Cannot open first.txt: $!";
> open SECOND, "< second.txt" or die "Cannot open second.txt: $!";
>
> chomp( my @first = <FIRST> );
> chomp( my @second = <SECOND> );
>
> close SECOND;
> close FIRST;
>
> open THIRD, "> third.txt" or die "Cannot open third.txt: $!";
>
> foreach ( @second )
> {
> foreach my $word ( @first )
> {
> print THIRD "$word$_\n";
> }
> }
According to the OP's spec this should be changed to:
open SECOND, "> second.txt" or die "Cannot open second.txt: $!";
foreach my $word ( @first )
{
foreach ( @second )
{
print SECOND "$word$_\n";
}
}
close SECOND;
:-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]