arrays - Perl: dereferencing an hash of hash of hashes -
consider sample code:
$var1 = { 'en' => { 'new' => { 'style' => 'defaultcaption', 'tts:fontstyle' => 'bold', 'id' => 'new' }, 'defaultcaption' => { 'tts:textalign' => 'left', 'tts:fontweight' => 'normal', 'tts:color' => 'white', } }, 'es' => { 'defaultspeaker' => { 'tts:textalign' => 'left', 'tts:fontweight' => 'normal', }, 'new' => { 'style' => 'defaultcaption', 'tts:fontstyle' => 'bold', 'id' => 'new' }, 'defaultcaption' => { 'tts:textalign' => 'left', 'tts:fontweight' => 'normal', } } }; i return reference, return \%hash
how dereference this?
%$hash. see http://perldoc.perl.org/perlreftut.html more information.
if hash returned function call, can either:
my $hash_ref = function_call(); $key (keys %$hashref) { ... # etc: use %$hashref dereference or:
my %hash = %{ function_call() }; # dereference to access values within hash, can use -> operator.
$hash->{en}; # returns hashref { new => { ... }. defaultcaption => { ... } } $hash->{en}->{new}; # returns hashref { style => '...', ... } $hash->{en}{new}; # shorthand above %{ $hash->{en}{new} }; # dereference $hash->{en}{new}{style}; # returns 'defaultcaption' string
Comments
Post a Comment