brycen has asked for the wisdom of the Perl Monks concerning the following question:
I expected this to print:#!/usr/local/bin/perl use strict; my $foo = 1; my $fum = 1; print STDERR "variables are now: $foo $fum\n"; &foo(); my $foo = 2; $fum = 2; print STDERR "variables are now: $foo $fum\n"; sub foo { print STDERR "variables are now: $foo $fum\n"; }
Could some kind Monk offer enlightenment, as to why my expectations were dashed? (Tested on perl 5.8.8 and Perl 5.10.0, with and without the in-this-case-helpful -w flag).variables are now: 1 1 variables are now: 1 2 variables are now: 2 2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: What is it I don't understand about perl scoping?
by jettero (Monsignor) on Jul 08, 2009 at 20:06 UTC | |
by brycen (Monk) on Jul 08, 2009 at 20:13 UTC | |
Re: What is it I don't understand about perl scoping?
by JavaFan (Canon) on Jul 08, 2009 at 20:03 UTC | |
Re: What is it I don't understand about perl scoping?
by Utilitarian (Vicar) on Jul 09, 2009 at 08:31 UTC | |
Re: What is it I don't understand about perl scoping?
by YuckFoo (Abbot) on Jul 09, 2009 at 18:18 UTC | |
Re: What is it I don't understand about perl scoping?
by youlose (Scribe) on Jul 09, 2009 at 12:05 UTC | |
Re: What is it I don't understand about perl scoping?
by mattford63 (Sexton) on Jul 09, 2009 at 21:00 UTC | |
Re: What is it I don't understand about perl scoping?
by kubrat (Scribe) on Jul 13, 2009 at 16:47 UTC |
Back to
Seekers of Perl Wisdom