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

Re: Is it hash??

by Cristoforo (Curate)
on Jun 26, 2018 at 02:02 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2021-04-20 20:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found