in reply to Re: $" seems not to be working
in thread $" seems not to be working
Might as well make the code as generic as possible ...
Of course, if you didn't need those curlies, the code would look even better ...#! perl -slw use strict; my %fhs; my $d = '|'; while(<>) { my ($first, $rest) = m[(^.*?)\Q${d}\E(.*$)]; open $fhs{$first}, '>>', $first or die "Couldn't open $first:$!" unless $fhs{$first}; print { $fhs{$first} } $rest; }
</nitpick>#! perl -slw use strict; my %fhs; my $d = '|'; while(<>) { my ($first, $rest) = m[(^.*?)\Q${d}\E(.*$)]; my $fh = $fhs{$first} ||= do { IO::File->new('>>', $first) || die "Couldn't open $first:$!" }; $fh->print($rest); }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|