I like the autovivification in 5.6.0:
#!/usr/bin/perl use strict; use warnings; { my %file_handle; while (<DATA>) { my ($id, $category, $sub_category, $code, $description, $pictu +re) = split /\|/; # massage data into a printable string $file_handle{$sub_category} ||= get_handle($sub_category); print {$file_handle{$sub_category}} "something\n"; } } # As %file_handle goes out of scope # all file handles close implicitly sub get_handle { my $file_name = shift; open my $fh, '>', $file_name or die "Cannot write to $file_name: $ +!"; return $fh; } __END__ 0|OFFICE EQUIPPMENT|PEN|PDS01|an ordinary pen|pen.gif 1|OFFICE EQUIPPMENT|PEN|PDS02|another pen|pen2.gif 2|OFFICE EQUIPPMENT|PAPER|PA003|white sheets to write on|paper.gif 3|OFFICE EQUIPPMENT|PEN|PDD50|the greatest pen|pen50.gif 4|OFFICE EQUIPPMENT|PEN|PDS01|an ordinary pen|pen.gif
In reply to Re: About Filehandles
by CharlesClarkson
in thread About Filehandles
by Chady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |