in reply to handler performance question
If the number of make/model pairs isn't likely to get too out-of-hand, you can also cache handles:
Then your main loop is reduced to:{ my (%handles, %did_mkdir); sub get_out_file { my ($make, $model) = @_; if (!defined $handles{$make}{$model}) { if (! $did_mkdir{$make} && ! -d "$out_dir/$make") { system "mkdir -p $out_dir/$make"; $did_mkdir{$make} = 1; } open $handles{$make}{$model}, "$out_dir/$make/$model" or die $!; } return $handles{$make}{$model}; } }
and all of the handles are closed at the end of execution. If this doesn't run you up against your filehandle limit, it will save you any number of unnecessary opens and mkdirs. If it does, well then you're going to have to start worrying about discarding entries from the cache, but you also have to ask yourself whether performance trumps complexity in that case. :)while (<>) { my ($make, $model) = split /,/, $_, 4; my $out = get_out_file($make, $model); print $out $line; }
In Section
Seekers of Perl Wisdom