[Melbourne-pm] Closures and scope warnings

Jacinta Richardson jarich at perltraining.com.au
Tue Jul 27 20:34:26 PDT 2010

Toby Corkindale wrote:
> Hmm,
> here's something that caught me out.. probably because it's not great 
> practice. (But it is a common theme in using DBIx::Class transactions)
> my $thing;
> sub { my $thing = 'wibble' }->();

This isn't just constrained to this circumstance, and is probably normally 
considered a feature.  Consider:

my $name = "Jacinta";


#### much later

sub name {
	my $name = shift;

	print "$name\n";

Would you *really* want every subroutine which creates variables which shadow 
top-level variables to warn about such?  I don't think Perl distinguishes 
between your case and mine.


More information about the Melbourne-pm mailing list