[sf-perl] oddity with an exported and localized variable

David Lowe j.david.lowe at gmail.com
Mon Nov 30 23:54:39 PST 2009

Joe et al. -

On Thu, Nov 26, 2009 at 12:23 AM, Joe Brenner <doom at kzsu.stanford.edu> wrote:
> The point here is that the exported sub appears to be
> seeing the value the variable was assigned in the module,
> rather than seeing the current value assigned in the script.
> This isn't the way dynamic scoping is supposed to work,
> correct?  Any ideas what might be going on here?

This surprising behavior is documented in 'perldoc perlmod':

The fix is to change both the export and import lists to
'*exported_variable' instead of '$exported_variable'; making these
changes causes the example code to behave as expected.

The bug, IMO, is that neither the documentation for 'Exporter' nor
'local' mention it. OTOH the documentation for Exporter *does* say
(paraphrasing) "DO NOT EXPORT VARIABLES"... and the documentation for
'local' *does* say (paraphrasing) "DO NOT USE LOCAL EXCEPT FOR MAGIC
PUNCTUATION VARIABLES"... so there's a bit of poetic justice at work
here, too ;)

David Lowe

More information about the SanFrancisco-pm mailing list