Jakob Kofoed wrote:
Hi,
I would like to load a file to a hash so I will be able to call a
specific number in that hash:
use strict;
use warnings;
my %hash = ();
open IN, "< $ARGV[0]" || die "could not open $ARGV[0]\n";
my $cnt = "0";
while (<IN>) {
chomp;
%hash = ( $cnt => $_ );
$cnt++;
}
print $hash{"837"};
This works fine with the last line only! how do I append to my hash?
and secondly: here I use a counter to get a specific "line" in the
hash - does a hash have a "build in" counter to refer to?
Thanks in advance.
Jakob
why using a hash .. an array is what you are looking for.
my @array;
my $cnt;
open (IN,"<",shift) or die $!;
while(<IN>)
{
chmop;
$array[$cnt]=$_;
$cnt++;
}
MNibble
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>