in reply to Re^2: calling subroutines
in thread calling subroutines

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

Replies are listed 'Best First'.
Re^4: calling subroutines
by bobosm (Initiate) on Oct 12, 2013 at 16:34 UTC
    Tnx man :) Now I understand the problem.