in reply to Unable to extract value from hash table

Hello NsshB,

tybalt89 beat me to it, but here’s the answer I was about to post, which expands a bit on the answer he’s given:

If you output the value of $name like this:

if ($line[0] =~ /STAT/) { my $name = $line[5]; print "name = >$name<\n"; my $status = $line[4];

you will see that the first occurrence prints as name = > ZELDA<, which shows there is an extra space in the string. And since %table has no key named ' ZELDA', the table lookup fails.

A simple way to fix this is to change this line:

my @line = split (/,/,$line);

to this:

my @line = split (/\s*,\s*/,$line);

which treats any whitespace as part of the delimiter.

BTW, you really should begin every script with:

use strict; use warnings;

— and then you’ll need to declare %table before the loop:

chomp (my @lines = <FILE>); my %table; foreach my $line (@lines) { ...

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,