Re: Append to hash

2005-07-15 Thread Chris Charley
Jakob Kofoed wrote: I have a file with some navigation (x and y's) and needed to fill in point between exiting points. My in put file: 60 6174210 600017 6174213 600028 6174206 600035 6174216 600045 6174209 For calculation I need to use line 1 and 2 for calculating one point and then

Re: Append to hash

2005-07-15 Thread MNibble
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 () { chomp; %hash = ( $cnt => $_ );

Re: Append to hash

2005-07-15 Thread Jakob Kofoed
I have a file with some navigation (x and y's) and needed to fill in point between exiting points. My in put file: 60 6174210 600017 6174213 600028 6174206 600035 6174216 600045 6174209 For calculation I need to use line 1 and 2 for calculating one point and then line 2 and 3 and so

Re: Append to hash

2005-07-15 Thread John W. Krahn
Jakob Kofoed wrote: Hi, Hello, 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"; That will never die() because of the high precedence of the ||

Re: Append to hash

2005-07-15 Thread Jakob Kofoed
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 k

Re: Append to hash

2005-07-15 Thread Xavier Noria
"; while () { 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 i

Append to hash

2005-07-15 Thread Jakob Kofoed
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 () { chomp; %hash = ( $cnt => $_ ); $cnt++; } print