in reply to passing refs to subs

all in all this is the old dilemma "pass by value" vs. "pass by reference" when you pass by reference you can alter the content of the original variable... (unless you make a copy inside the subroutine, but then where is the gain?)

Replies are listed 'Best First'.
RE: Re: passing refs to subs
by davorg (Chancellor) on Oct 10, 2000 at 12:18 UTC

    Actually, it's not quit that simple. Perl's standard calling convention isn't pass by value. The values that you get in @_ are aliases to the original variables, so changing @_ will change the values outside the subroutine, as this simple test demonstrates.

    my $x = 1; mult($x); print "$x\n"; sub mult { $_[0] *= 10; }
    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me