in reply to Assistance with Comma parse
Um ... I think this is what you're asking for ...
while (<>) { my ($node) = split /,/; open $node, ">>$node" or die "a horrible death!"; print $node $_; close $node; }
There are slicker ways though. Other than opening a file each time, you could cache the opened filehandles and just write to the already opened ones (mayn't be too useful if you've got many many files to open) Here's some code (untested, caveat lector):
my %cache; while (<>) { my ($node) = split /,/; unless ($cache{$node}) { open $node,">>$node" or die "a horrible death"; $cache{$node}++; } print $node $_; } for my $n (keys %cache) { close $n; }
|
|---|