I want to restrict the scope of number.
It's not clear to me, but it seems possible you're actually asking "I want to restrict the scope of the $number scalar." If that's the case, then one way is to establish an independent scope { ... } for the variable:
c:\@Work\Perl\monks>perl -wMstrict -le
"my $number = 42;
print '$number before independent scope == ', $number;
;;
{ my $number = 8;
print '$number in independent scope == ', $number++ for 1 .. 5;
}
;;
print '$number after independent scope == ', $number;
"
$number before independent scope == 42
$number in independent scope == 8
$number in independent scope == 9
$number in independent scope == 10
$number in independent scope == 11
$number in independent scope == 12
$number after independent scope == 42
Update: Discussions of scoping can be found throughout perlsyn and among the Tutorials in the Variables and Scoping section.
Give a man a fish: <%-(-(-(-<
|