in reply to Making a variable in a sub retain its value between calls
Since $counter exists before the sub is called, the sub inherits the variable and updating it should work fine.#!/usr/bin/perl use warnings; use strict; my $counter = 0; &mySub; &mySub; &mySub; sub mySub { print "My Value is ", $counter++, "\n"; }
|
---|