Archive: 2012/06

how to refer complex perl variables

just for my memo… Here is sample code.

#!/usr/bin/perl
use Data::Dumper;

my $arg;
$arg = {'first' => 'aaa',
    'second' => 'bbb'};
print Dumper($arg);
print $arg->{'first'} . "\n"; #print 'aaa'

undef($arg);

my $arg;
$arg->{'1'} = {'1-1' => 'value1',
        '1-2' => 'value2'};
$arg->{'2'} = {'2-1' => 'value3',
        '2-2' => 'value4'};
print Dumper($arg);
print $arg->{'1'}->{'1-2'} . "\n"; #print 'value2'
print $arg->{'2'}->{'2-2'} . "\n"; #print 'value4'
print $arg->{'2'}->{'2-3'} . "\n"; #print NULL