2007/8/28, Chris <[EMAIL PROTECTED]>:
> Yet another problem from Intermediate Perl, I've been given a log
> file. Here is a sample of its contents:
>
> Gilligan: 1 coconut
> Skipper: 3 coconuts
> Gilligan: 1 banana
> Professor: 3 coconuts
> MaryAnn: 2 papayas
> Thurston: 2 mangoes
>
> I am supposed to read the log file and output its contents into a
> series of files called gilligan.info, maryann.info, etc. In the end I
> should I have a .info file for each character. In the file will be
> information pertaining to the character. For example, gilligan.info
> will have
> Gilligan: 1 coconut
> Gilligan: 1 banana
>
while (<>) {
my ($f) = (split)[0];
$f=~s/://;
$f=lc($f);
open FD,'>>',"$f.info" or die $!;
print FD $_;
close FD;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/