in reply to Pass by Value does not work

You haven't made a 'deep' copy of your data structure, which means the array references are still pointing to the original data. You've only copied the references themselves...

Replies are listed 'Best First'.
Re^2: Pass by Value does not work
by Bloodnok (Vicar) on Feb 21, 2009 at 12:17 UTC
    merlyn, as is his won't, wrote an extremely descriptive & helpful article on this very topic i.e. the problem you've unwittingly encountered, some while ago in the UNIX Review.

    A user level that continues to overstate my experience :-))
Re^2: Pass by Value does not work
by swampyankee (Parson) on Feb 21, 2009 at 12:44 UTC

    Not to sound too dense, but doesn't Perl always use "pass by reference," in that changing anything in the $@ array will change its values in the calling routine?

    Of course, the language I grew up using always passes by reference, so it usually takes a mental effort to assume any changes in a sub to passed variables don't propagate upstream.


    Information about American English usage here and here. Floating point issues? Please read this before posting. — emc

      I suppose the OP was thinking that - due to the @ali = @_ - the entire data structure would be copied...  And the "pass by value" was probably referring to left_triangle(@xx) vs. left_triangle(\@xx) — with the "values" being the array refs.   (Only the OP can tell for sure, though, what his/her expectation had been.)

        Your supposition makes perfect sense to me, and it was something I didn't even think of.


        Information about American English usage here and here. Floating point issues? Please read this before posting. — emc