in reply to Re: array reference madness
in thread array reference madness

Indeed; the extra referencing is being added by the \&buildlist($_), which is an unnecessary complication. There's no need to build a reference here at all, since buildlist() already explicitly returns one, and it's arguably confusing because \& is normally used to take a reference to a subroutine, not to a return value.

Removing the \& there would enable all the ${$$...}-type constructions to be simplified, so for example the assignment to @tmp would then become just @{$ref->[3]}. This is probably a Good Thing.

Replies are listed 'Best First'.
Re^3: array reference madness
by Anonymous Monk on Mar 14, 2009 at 22:42 UTC
    "Extra-referencing?!!" I was thinking the \& and the \@ matched, wrt the "type" of the return value. So you've given me something to think about -- I'll try and apply this. Thanks much! ps. the exercise is 5-2. I like the book, it's well structured ;)
      use O qw' Deparse -p '; print \&reference; # real ref print \&call(1); # ref to return value print \( &call(1) ); # same as above, ref to return print \( call(1) ); # same as above, ref to return __END__ print((\&reference)); print(\(&call(1))); print(\(&call(1))); print(\(call(1))); __DATA__