Hi,

Thanks both for the code hint and the note.

Cheers.

snip..........
> 
> To append to %hash you just make an assignment this way:
> 
>      $hash{$cnt} = $_;
> 
> and move the initialization above the while:
> 
>      %hash = ();
> 
> As a side note, you know regular hashes accept only strings as keys.
> You don't need to take the trouble to force strings for hash keys
> though, Perl knows he needs a string there and does the job for you,
> coming up with a string from what you happened to use as key. In
> particular you can use integers directly:
> 
>      my $cnt = 0;
>      # ...
>          $hash{$cnt} = $_;
>      # ...
>      print $hash{837};
> 
> which makes the code more natural, given that $cnt is a counter.
> 
> For that particular problem the standard module Tie::File is really
> handy:
> 
>      use Tie::File;
>      tie @lines, 'Tie::File', $ARGV[0] or die;
>      print $lines[837];
> 
> -- fxn
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to