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

It is not necessary to associate data with filenames, just data with line numbers. So, we construct a hash with line numbers as keys.

I'm sure there's a reason, but it's not apparent to me... why use a hash with numbers as keys instead of an array of array references?



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

  • Comment on Re: Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)

Replies are listed 'Best First'.
Re: Re: Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)
by bwana147 (Pilgrim) on Jun 01, 2001 at 20:21 UTC

    I guess it's because not every line is interesting. Suppose you want to find the line numbers where a token is found in a collection of files, but don't care about comments, why would you want to keep array elements which are uninteresting? You'd need to filter them out later anyway, with something like "grep { @$_ } @list". Using "keys %list" is altogether easier.

Re: Re: Larry Gets The Colon. (selective addition of an arrayref to a hash) (code)
by Anonymous Monk on Oct 14, 2003 at 09:29 UTC
    Without the railroads, how would we ge to the airport ;-)