Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: hash problem

by davidj (Priest)
on Jun 08, 2005 at 09:02 UTC ( #464601=note: print w/ replies, xml ) Need Help??


in reply to hash problem

First, I think you might have an error in the code you submitted. I assume that

$names{$refnum} = $str;
should be
$names{$ref} = $str;
Second, the reason the code is dying is because on the last line,  $names{$number} does not exist.

It might be a good idea to take a look at what $names is actually holding after the loop. A good way to see that is to use Data::Dumper

#!/usr/bin/perl use Data::Dumper; %names; { open(name, "<data/gly.txt"); while(<name>) { ($ref, $str) = split /\|/; $names{$ref} = $str; } } print Dumper(%names);
This will help you track down the problem.

davidj


Comment on Re: hash problem
Select or Download Code
Re^2: hash problem
by Anonymous Monk on Jun 08, 2005 at 09:08 UTC
    it would appear that the number of lines in the hash is double of that in the gly file. $var1 = undef $war2 = 'h20' etc
      The hash has not doubled. Rather, $var1 = undef is the key to the first hash element, $var2 = 'h20' is the value of the first hash element, etc.

      The good news is, this verifies the problem. That is, your keys are empty. Please show us the content of the text file you are using. That will certainly help us help you resolve the problem.

      davidj

        thanks for ur time people, i have corrected the fault cheers

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://464601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (15)
As of 2014-12-18 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls