[Israel.pm] A Perl 5 Gotcha

sawyer x xsawyerx at gmail.com
Fri Mar 6 08:47:41 PST 2009


Bad choice of words. I confused it with calling a subroutine with &,
such as &print_name().
The problem with putting the subroutines at the end is that it makes
the previous variables in the code apparent to that subroutine. It's
not lexically correct and provides an unclean environment for the
subroutine.

my $name = 'sawyer';

sub print_name {
    # this shouldn't work because the subroutine
    # is a different namespace, but it does
    # because the subroutine sees all the previous
    # variables and the namespace isn't clean
    print "$name\n";
}

On Fri, Mar 6, 2009 at 6:27 PM, Yitzchak Scott-Thoennes
<sthoenna at efn.org> wrote:
>
> On Fri, March 6, 2009 8:18 am, sawyer x wrote:
> > Beyond that, you're defining the subroutine at the end, which exposes
> > it to @_.
>
> What do you mean by that?
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl



More information about the Perl mailing list