Question

$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

Was it helpful?

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.

OTHER TIPS

%$ is just the syntax for dereferencing a referenced hash. Take a look here. The \% is for referencing a hash. So store is a function which needs to called with a hashref (1. Param).

The %some_hash= %$stored_var; Part is to copy a hashref to a new hash. You need to dereference it and then it can be copied.

%$foo is de-referencing a reference $foo to a hash, so a line

%bar = %$foo;

is (shallow) copying the contents of a hash referenced by a scalar variable into another hash, accessed more directly by a hash variable.

In some ways yes this is "just syntax" i.e. just a way of de-referencing. One important detail is that store and retrieve will not work directly to serialise hashes or arrays, so you have to use references to them (in scalar values).

The line would fail if $foo was not a reference to a hash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top