Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Is it hash??

by Cristoforo (Curate)
on Jun 26, 2018 at 02:02 UTC ( [id://1217417]=note: print w/replies, xml ) Need Help??


in reply to Is it hash??

You might be using constants (here named KNOWN and UNKNOWN). If so, where they are mentioned in your code, they would be unquoted (KNOWN and not "KNOWN"). Here is an example using named constants.
#!/usr/bin/perl use strict; use warnings; use constant {KNOWN => 1, UNKNOWN => 0}; my $test; $test -> {'RecordType'} = UNKNOWN; #case 1 if($test ->{'RecordType'}){ # if $tset->{'RecordType'} == any 'true' v +alue, i.e 1 print "case1 is known\n"; } else { print "case1 is unknown\n"; } #case 2 if($test ->{'RecordType'} == KNOWN){ # if $tset->{'RecordType'} == 1 print "case2 is known\n"; } else { print "case2 is unknown\n"; }
The run produces this output:
case1 is unknown case2 is unknown
On another point, $test is not a hash but is used as a hash reference. So, it is used as $test->{RecordType} and not $test{RecordType}

Constants are usually used to make code more clear (names instead of numbers).

Constants are explained here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found