in reply to Re^3: Sub hash param by reference
in thread Sub hash param by reference

Hello GrandFather, thank you for your feedback and Wow, I never know param can do like that. I'm not quite understand what is $_[0] but I tested with it and it works well.

sub doSub2 { # use name var instead of $_[0] so can easier to recall it my ($ref_value) = \$_[0]; $$ref_value = "Hello alias"; }

Replies are listed 'Best First'.
Re^5: Sub hash param by reference
by Athanasius (Archbishop) on Jul 10, 2016 at 08:44 UTC

    Hello hankcoder,

    I'm not quite understand what is $_[0]

    The special variable @_1 is documented as follows:

    Within a subroutine the array @_ contains the parameters passed to that subroutine. Inside a subroutine, @_ is the default array for the array operators pop and shift.

    Now, in Perl2 you access the individual elements of array @my_array as $my_array[0], $my_array[1], $my_array[2], .... (Note that the first element has index zero.) In the same way, the array @_ (which is named “ _ ”) has elements $_[0], $_[1], $_[2], .... So $_[0] is the first parameter passed to the subroutine.

    1You can also call it @ARG if you use English; — see perlvar#General-Variables.
    2That is, Perl 5 and earlier. I believe Perl 6 uses a different syntax.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Thanks Athanasius for the clear explanation.