Passing variables into a subroutine through osmosis (except for specific situations that you don't need to worry about yet) is a terrible habit to get into.
To remedy your immediate problem, remove the line from your sub, "my $num1;", because it's creating a lexical variable inside the sub that masks the variable created in your for loop. But, while that will fix the immediate problem, it will start you down the wrong path. What you should be doing is passing parameters into your subroutine like this:
my $value = "whatever"; some($value); sub some { my( $param ) = @_; print "$param\n"; }
...or use shift, or any of the other means demonstrated when you read the document "perlsyn", by typing perldoc perlsyn on your local system with Perl installed.
Dave
In reply to Re^3: calling subroutines
by davido
in thread calling subroutines
by bobosm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |