I figured it out

$item2save{'cpu01'}  = IO::File->new("> cpu01.out");
$item2save{'cpu02'}  = IO::File->new("> cpu02.out");
$item2save{'cpu03'}  = IO::File->new("> cpu03.out");
...

print { $item2save{ $itemfound } } <stuff to write to the respective file>

where $itemfound can have the values that match the keys in the
%item2save hash ...

sorry to bug the list

-pete


On Mon, Mar 5, 2012 at 10:48 AM, Benjamin Foote <p...@bnf.net> wrote:
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $logfile = $ARGV[0];
>
> open (LOG, $logfile) or die "can't open $logfile: " . $!;
>
> while (my $line = <LOG>) {
>   chomp($line);
>   my @cols = split /\s+/, $line;
>   my $cpufile = shift @cols;
>   open (OUT, ">> " . $file") or die "can't open $cpufile: " . $!;
>   print OUT join " ", @cols;
>   close OUT;
> }
>
> Benjamin Foote
> http://pdxstump.com - a search engine and news aggregator for Portland
> http://bnf.net - Linux and Java Consulting
> b...@bnf.net
> 503-313-5379
> @pdxstump on twitter
>
>
>
> On Mon, Mar 5, 2012 at 10:26 AM, Pete Lancashire 
> <p...@petelancashire.com>wrote:
>
>> my brain this morning is blocked on this one
>>
>> I have a data file
>>
>> cpu01  value value value
>> cpu02  value value value
>> cpu03  value value value
>> ...
>> cpu01  value value value
>> cpu02  value value value
>> cpu03  value value value
>> ...
>> cpu01  value value value
>> cpu02  value value value
>> cpu03  value value value
>> ...
>>
>> column 1 can be cpu\d+ and cpu_all
>>
>> I want to open files for writing, one for each unique value in the first
>> column.
>> so that if the value f the data in the first column is "cpu01" then
>> write to the file
>> with the FH of $cpu01
>>
>> This has to be simple ...
>>
>> -pete
>> _______________________________________________
>> PLUG mailing list
>> PLUG@lists.pdxlinux.org
>> http://lists.pdxlinux.org/mailman/listinfo/plug
>>
> _______________________________________________
> PLUG mailing list
> PLUG@lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
_______________________________________________
PLUG mailing list
PLUG@lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to