in reply to directly modify hash from subroutine

Ok, yeah if I replace $_ with $_[0] then it works.
I guess I didn't understand the way function parameters were passed. So the arguments are always in @_, not $_, is that correct?
  • Comment on Re: directly modify hash from subroutine

Replies are listed 'Best First'.
Re^2: directly modify hash from subroutine
by chromatic (Archbishop) on Sep 05, 2009 at 00:26 UTC

    That is (almost always) correct. There's a special case related to subroutine prototypes in Perl 5.10, but you can safely and successfully ignore that for a very, very long time.

Re^2: directly modify hash from subroutine
by biohisham (Priest) on Sep 05, 2009 at 19:56 UTC
    Great, well you know that @_ would hold the arguments passed to a subroutine and you correlated that with array element indexing. Function (subroutines) parameters are passed either directly or by reference, but you have to remember:
    • using & to call a subroutine would disable prototype checking on the arguments if you have specified a subroutine that accepts certain types of arguments.
    • modifying a reference inside a subroutine would modify the original data as is the case with references modification in general.


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.