in reply to passing reference to subroutine
I think you've removed too much context for any answer to actually solve the problem you haven't described. However I'll address the question as posed just in case it does have some bearing on your actual problem.
The sub call passes a reference to an array into the sub - so far so good. Note though that @struct outside the sub has nothing to do with @struct inside the sub: It would be clearer to choose a different name for one of the arrays.
In the sub $ref gets a copy of the passed in array reference. A copy of the elements in the referenced array is then made and placed into the sub's @struct - a copy note!
undef @struct; (better written as @struct = (); btw) clears out the array containing a copy of the original array.
The important thing to realise here is that nothing done in the sub affects the original array because all the work is done on a copy of the contents of the original array.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: passing reference to subroutine
by BrowserUk (Patriarch) on Oct 28, 2011 at 08:18 UTC | |
|
Re^2: passing reference to subroutine
by asthaonard (Acolyte) on Oct 28, 2011 at 08:31 UTC | |
by GrandFather (Saint) on Oct 28, 2011 at 08:40 UTC | |
by asthaonard (Acolyte) on Oct 28, 2011 at 08:54 UTC | |
by RichardK (Parson) on Oct 28, 2011 at 10:03 UTC |