in reply to Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)
I'd do this:
$statistics{$line_number} ||= []; push @{ $statistics{$line_number} }, $thisline;
If $statistics{$line_number} is already an array ref, it is considered true, so the ||= operator won't affect it. Otherwise, it becomes an empty array ref.
Whatever happens on the first line, you know on the second line that $statistics{$line_number} is an array ref, so you can push without further pondering.
HTH
--bwana147
|
|---|