Re: Print to new file for each results
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Tue, 29 Aug 2006 21:42:23 -0700
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
.
- References:
- Print to new file for each results
- From: Ron McKeever
- Print to new file for each results
- Prev by Date: Print to new file for each results
- Next by Date: Re: splitting strings
- Previous by thread: Print to new file for each results
- Next by thread: Re: Print to new file for each results
- Index(es):