Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push onto a dereferenced array gives warning

Tags:

perl

I have the code:

push @$args{"ARRAY"}, "value";

This gives warning saying:

push on reference is experimental at ...

If I just use block around the array:

push @{args{"ARRAY"}}, "value";

Then the warning disappears. Why is this happening?

like image 381
SwiftMango Avatar asked Mar 22 '15 04:03

SwiftMango


1 Answers

@$args{"ARRAY"} is equivalent to @{$args}{"ARRAY"}, not @{$args{"ARRAY"}}. From perlref, section "Using References":

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. Consider the difference below; case 0 is a short-hand version of case 1, not case 2:

   $$hashref{"KEY"}   = "VALUE";       # CASE 0
   ${$hashref}{"KEY"} = "VALUE";       # CASE 1
   ${$hashref{"KEY"}} = "VALUE";       # CASE 2
   ${$hashref->{"KEY"}} = "VALUE";     # CASE 3
like image 57
Slade Avatar answered Oct 20 '22 08:10

Slade