in reply to Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)

One minor improvement would be to not repeat the test, by returning from the sub or continuing the loop if you just added it:
# if we haven't hit this line yet, add an array # reference to %statistics at this line number. if (not defined $statistics{$line_number} ) { $statistics{$line_number} = [ $thisline ]; next; # or return or whatever to avoid next push } # now we know that we have an array ref # and all we have to do is push it. push @{ $statistics{$line_number} }, $thisline;
  • Comment on Re: Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)
  • Download Code

Replies are listed 'Best First'.
Re: Re: Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)
by Vynce (Friar) on Jun 02, 2001 at 12:43 UTC
    or, heaven help us, if ... else construction.