ulofb has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to dereference all references stored in an array ? With other words : How can I access the values, references stored in an array are pointing to ?
my ($a, $b, $c) = (1, 2, 3); my @arrayOfRefs = \($a, $b, $c); my @arrayOfValues = {@arrayOfRefs};
This code-snippet doesn't work. Any idea how to proceed ? Thanks in advance

Replies are listed 'Best First'.
Re: dereference references in an array
by tobyink (Canon) on Sep 01, 2014 at 22:53 UTC
      Yes, of course that it is. Thank you very much. ulofb
Re: dereference references in an array
by locked_user sundialsvc4 (Abbot) on Sep 02, 2014 at 03:08 UTC

    Also note here the use of a doubled dollar-sign, e.g. $$varname, as a legitimate and somewhat more-succinct alternative to the use of the -> dereference operator.   (Dunno, it might be the only one that works given this particular use of map.)   I happen to prefer it, and do use it often ...

      Just a note from perlref because people make this mistake:

      ... $$arrayref[0] = "January"; $$hashref{"KEY"} = "VALUE";

      It's important to understand that we are specifically not dereferencing $arrayref[0] or $hashref{"KEY"} there. The dereference of the scalar variable happens before it does any key lookups. ...

      Because of being able to omit the curlies for the simple case of $$x, people often make the mistake of viewing the dereferencing symbols as proper operators, and wonder about their precedence. If they were, though, you could use parentheses instead of braces. That's not the case.