On Thursday 06 May 2004 02:45 am, you wrote:
> Beau,
> 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.
>
> HTH
>
> srikanth

srikanth - thanks.

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.

Aloha => Beau;

>
> [EMAIL PROTECTED] (Beau E. Cox) writes:
> > Hi -
> >
> > This sample looks funny ( please don't say 'why would
> > you ever want to do that?' ) but it is part of a much
> > larger project. This script:
> >
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > _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;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to