in reply to Re^4: Help with references
in thread Help with references
In addition to what thor says, it's important to remember that each time your code enters a block that has a my variable in it, like this sub, it creates a completely new variable (at least conceptually). So when two calls to the sub both return \@a1, they're returning completely different and unrelated variables. This is different than if \@a1 were a global variable, in which case both would return the exact same reference (and so changes to one would affect the other).
This is one of the really nice things about Perl over languages like C, where returning a local variable from a sub is a really bad idea.
|
|---|