P is for Practical | |
PerlMonks |
Re^3: problems passing variables between subroutineby CountZero (Bishop) |
on Sep 05, 2012 at 13:37 UTC ( [id://991854]=note: print w/replies, xml ) | Need Help?? |
The error is not in the subroutine. In your script when you call create_output (@array_of_lines, $entry_no_new); the array is empty since you never put anything into @array_of_lines. You are getting yourself confused because in the look_through_file subroutine you also declare an @array_of_lines array and fill it with data. BUT as this is a lexical array scoped to this subroutine only (and totally separate of the lexical @array_of_lines declared in the main body of your script), it will simply disappear at the end of the subroutine, taking all its data with it. There are two solutions:
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics
In Section
Seekers of Perl Wisdom
|
|