Click to See Complete Forum and Search --> : perl hashes


artwise
02-18-2003, 11:47 PM
I am struggling with hashes in perl. I am trying to declare a hash, but with no keys and values(empty one). Then I want to populate keys and values from a certain file with some structure(simple text file). I have ActiveState's perl 5.8.

Example:
%glMap ();


the file looks like:
key1|val1
key2|val2
...
How can I do it?

jeffmott
02-19-2003, 09:29 AM
my %hash;

while (<DATA>) {
chomp;
my($key, $val) = split /\|/, $_, 2;
$hash{$key} = $val;
}

__DATA__
key1|val1
key2|val2

celebguy_dv
03-04-2003, 01:20 AM
http://banners.dollarmachine.com/pic/2014000/hal001.gif (http://www.kinkyceleb.com/1261795520)