in reply to Re: passing reference to subroutine
in thread passing reference to subroutine

i see... but how would i avoid that copying? How should i dereference my variable correctly?

Replies are listed 'Best First'.
Re^3: passing reference to subroutine
by GrandFather (Saint) on Oct 28, 2011 at 08:40 UTC

    What do you really want to do? The dereference is as simple as undef @$ref; (see below for the entire updated sub), but I have the strong feeling that you are asking the wrong question and providing the wrong sample code. It seems extraordinary that you would call a sub just to clear an array!

    sub undef_ref { my $ref = shift; undef @$ref; print '=' x 20; print "\n"; print Dumper (@$ref); }
    True laziness is hard work

      Well, I'm trying to modify an array in a subroutine. I have chose to undef my array because... well... i thought it would be good example. I was wrong :)

      Your code works as expected.

      Thank you very much

Re^3: passing reference to subroutine
by RichardK (Parson) on Oct 28, 2011 at 10:03 UTC

    It's worth the time to have a look at perlreftut -- the simple reference tutorial :)