> > This is coz you have defined $arg1 and $arg2 to be
> local, hence when u
> > defined a new subroutine, a new sope is defined,
> and is beyond the scope of
> > $arg1 and $arg2. Hence the error.
> But wait, I thought 'my' variables were 'local to
> the enclosing
> block'. If you look at the enclosing block in my
> sample, it
> DOES include the nested subroutine.
> I guess I still don't understand.
Hi,
Not very sure but ...
since show_results is accessing a variable outside
its scope, it has become a closure. Also, it is a
nested sub-routine. So the first-time it is called,
both it and the calling func (_main) will refer to the
same variable. But when it is called the next time, it
will access its own copy of the two variables ($arg1
and $arg2) and hence the error message that the
variables will not remain shared.
HTH,
Alok
> > > _main();
> > >
> > > sub _main
> > > {
> > > my $arg1 = shift @ARGV;
> > > my $arg2 = shift @ARGV;
> > >
> > > show_results();
> > >
> > > sub show_results
> > > {
> > > print "$arg1 and $arg2\n"; # <- line 17
> > > }
> > > }
> > >
> > > gives the following warnings:
> > >
> > > [EMAIL PROTECTED]:~/src/bempl/junk$ perl ev2.pl mary
> jane
> > > Variable "$arg1" will not stay shared at ev2.pl
> line 17.
> > > Variable "$arg2" will not stay shared at ev2.pl
> line 17.
> > > mary and jane
> > >
> > > Can you nest subroutines? What do the warnings
> mean?
> > >
> > > Aloha => Beau;
>
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>