in reply to Stupid question
If you want to limit the scope of a lexical variable, you need to declare it inside a block, like this:
With use strict, that code doesn't compile, because the $bar in foo() hasn't been declared, which is the effect you want.#!/usr/bin/perl -w use strict; sub foo(); # main: { my $bar = "I can see you"; &foo; } sub foo() { print "inside foo: $bar\n"; return(0); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Stupid question
by code24 (Initiate) on Dec 07, 2000 at 02:42 UTC | |
by jeffa (Bishop) on Dec 07, 2000 at 02:51 UTC | |
by chipmunk (Parson) on Dec 07, 2000 at 02:52 UTC |