Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2020-09-20 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (120 votes). Check out past polls.

    Notices?