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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -