What do you expect this to do? There's no @data in your program; what does it contain?
'$short' => '$place',The key of this pair is the literal string $short and not the contents of the variable $short. Likewise the value of this pair is the literal string $place and not the contents of the variable $place. When you use a scalar variable in a double-quoted string, Perl interpolates the value of that variable in the string (that is, Perl looks up the value and inserts it into the string). There's no interpolation in single-quoted strings.
%stuff = ( ... )This will overwrite the hash at each iteration of the loop. Similarly, closing your (unused) filehandle within the body of the loop will close it multiple times.
I suspect you want a program more like:
use strict; use warnings; open my $fh, 'data.txt' or die "Can't read data.txt: $!\n"; my %stuff; while (<$fh>) { chomp; my ($short, $place) = split /\|/, $_; $stuff{$short} = $place; } close $fh;
... but that's a rough guess. (Because you're a novice, let me point out gently that naming a filehandle OUT when you open it for reading will confuse people.)
In reply to Re: novice with hash/data file question
by chromatic
in thread noob with hash/data file question
by bhall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |