Push to array reference

后端 未结 4 503
野的像风
野的像风 2020-12-29 02:40

Is it possible to push to an array reference in Perl? Googling has suggested I deference the array first, but this doesn\'t really work. It pushes to the defere

4条回答
  •  粉色の甜心
    2020-12-29 03:27

    $a is not $a_ref, ($a is the first comparison variable given to a sort{}, and $a[0] is the 0th element of the @a array).Never use $a, or $b outside of a custom sort subroutine, and the @a and @b array should probably be avoided to too (there are plenty of better choices)...

    What you're doing is assigning to $a_ref, an anonymous array, and then pushing onto it "hello", but printing out the first element of the @a array.

提交回复
热议问题