Ron McKeever wrote:
> I am tring to use part of someones elses code that creates a data file which
> prints
> out like this:
>
> ip|result|deptA|data
> ip|result|deptB|data
> ip|result|deptC|data
>
> My goal instead of having all the data in one big file is to loop this and
> create
> a file for each result.
>
> So I would have a deptA.out file with deptA info then a deptB.out
> file with dept b info and etc.
>
> This is not exactly doing what I need:
>
> [ snip ]
>
> How would I create a file for each hash then print to it??? Any help, thanks.
#!/usr/bin/perl
use warnings;
use strict;
my %filehandles;
while ( <DATA> ) {
my $key = ( split /\|/ )[ 2 ];
unless ( exists $filehandles{ $key } ) {
open $filehandles{ $key }, '>', "$key.out"
or die "Cannot open '$key.out' $!";
}
print { $filehandles{ $key } } $_;
}
__DATA__
ip|result|deptA|data
ip|result|deptB|data
ip|result|deptC|data
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>