in reply to Re: passing variables between subroutines
in thread passing variables between subroutines

It's best to avoid passing non-scalars around that way. I think you're generally better served by passing the references
my @test = (1,2); my @test2 = (3,4); foo(\@test,\@test2); sub foo { my ($array,$array2) = @_; print $_ ."\n" for(@{$array}); print $_ ."\n" for(@{$array2}); }

Replies are listed 'Best First'.
Re^3: passing variables between subroutines
by revdiablo (Prior) on Jan 16, 2006 at 18:57 UTC
    It's best to avoid passing non-scalars around that way

    I have to say I disagree with that as stated. Certainly, there are many cases where passing a reference is preferable, but it depends on the situation. My default is to pass a simple list and switch to passing references when there's a clear need. I'd even go so far as to say it's best to err on the side of not making references when they're not needed.

      So, can you give me an example of when it would not be a good idea to pass a reference to a non-scalar? I'm asking in earnest. I truly want to know.
Re^3: passing variables between subroutines
by blazar (Canon) on Jan 17, 2006 at 10:45 UTC
    It's best to avoid passing non-scalars around that way. I think you're generally better served by passing the references

    First of all the person you're replying to already pointed out that possibility in his post. Said this, I beg to differ with your claim and to stress that it is actually a possibility, albeit one that -as he also pointed out- turns into a necessity under certain circumstances. But generally speaking there are situations in which passing a reference is preferrable and others in which it is preferrable not to. However, stating a claim like that may easily turn into cargo culting the use of referencing and dereferencing all the time, which has already been observed around.