in reply to Is it hash??
The run produces this output:#!/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"; }
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}case1 is unknown case2 is unknown
Constants are usually used to make code more clear (names instead of numbers).
Constants are explained here.
|
---|