Search code examples
perlhashreferenceperl-data-structures

Regarding store and retrieve in Perl


$stored_var = retrieve("$batch_text");
%some_hash= %$stored_var;

i think that this is for retrieving some stored hash. what does the %$ signify? Is it just the syntax or does it have more involved meaning?

store \%batch_hash, "$batch_text";

I assume the above is used to store the hash. Here also I have the same doubt about \% as above


Solution

  • what does the %$ signify?

    $stored_var is a hash reference and %$ is used to dereference it.

    store \%batch_hash, "$batch_text";
    

    %batch_hash is a hash and \% is used to pass the reference, so in store subroutine, you are passing reference of batch_hash hash as first parameter and $batch_text variable as second parameter.