Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Using Hashes

by graff (Chancellor)
on Jun 20, 2003 at 06:55 UTC ( [id://267476]=note: print w/replies, xml ) Need Help??


in reply to Using Hashes

For one thing, you want to learn about using the <code> tag when posting code or other stuff that should look like code.

For another thing, your "if" expressions are much more verbose than they should be. Assuming that "low_count_no" and "high_count_no" are supposed to refer to the values of the third and fourth columns in your data file (e.g. numeric values 0 and 3 respectively, for this line: "A1","D2CHILDB1T3","0","3","0T3") -- and assuming that you are parsing the file correctly when you load it into your data structure -- your logic would normally look like this:

if ($cals_info{$cals_type}{low_count_no} != $cals_info{$cals_type}{hig +h_count_no}) { print $cals_info{$cals_type}{$cals_state_0}; } else { print $cals_info{$cals_type}{$cals_state_1}; }
Though for cases like this, I personally prefer to use the ternary operator:
print ($cals_info{$cals_type}{low_count_no} != $cals_info{$cals_type}{ +high_count_no}) ? $cals_info{$cals_type}{$cals_state_0} : $cals_info{$cals_type}{$cals_state_1};
But, as suggested in the earlier reply, the error report you're getting suggests that you are not parsing the data file correctly, and for at least the line that has "2EN" in it (if not other lines as well), one of those "count_no" elements is holding that last field, instead of the intended digit value.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found