Q:

What are the different ways to access the hash variables in perl

According to my basic understanding we can access the values of an hash as follows:
$hash_name{key1}{key2};       #In case of an nested hash 
$hash_reference->{key1}{key2} #if we have the reference to the hash instead of the hash we can access as 

But in in one the archived code I have seen as follows:
$sc1 = %par->{'a'}{'b'};
@a1 = %par->{'a'}{'c'};
%c3 = %par->{'a'}{'d'};

What does it actually mean? Can some one help me on this?

A:

All three variants you posted will produce a syntax error while under use strict, and an additional warning with use warnings on Perls older than Perl 5.22. The output I show here is from Perl 5.20.1.
use strict;
use warnings;

my $par = { a => { b => 1, c => 2, d => 3 } };

my $sc1 = %par->{'a'}{'b'};
my @a1 = %par->{'a'}{'c'};
my %c3 = %par->{'a'}{'d'};

__END__
Using a hash as a reference is deprecated at /home/foo/code/scratch.pl line 700.
Using a hash as a reference is deprecated at /home/foo/code/scratch.pl line 701.
Using a hash as a reference is deprecated at /home/foo/code/scratch.pl line 702.
Global symbol "%par" requires explicit package name at /home/foo/code/scratch.pl line 700.
Global symbol "%par" requires explicit package name at /home/foo/code/scratch.pl line 701.
Global symbol "%par" requires explicit package name at /home/foo/code/scratch.pl line 702.
Execution of /home/foo/code/scratch.pl aborted due to compilation errors.

Without strict and warnings, it will compile, but produce nonsense.
no strict;
no warnings;
use Data::Printer;

my $par = { a => { b => 1, c => 2, d => 3 } };

my $sc1 = %par->{'a'}{'b'};
my @a1 = %par->{'a'}{'c'};
my %c3 = %par->{'a'}{'d'};

p $sc1;
p @a1;
p %c3;

__END__

undef
[
    [0] undef
]
{
    ''   undef
}

That said, always use strict and use warnings for your Perl programs, and listen to the warnings it shows you.

