in reply to Sharing a variable between subroutines
Another possibility is to use local with global variables. This use is generally not recommended as global variables are generally a Bad Thing. However, you might at times find this useful. See tilly's Why I Like Functional Programming.
use strict; use warnings; use vars '$foo'; somesub(); print "\$foo is $foo\n"; sub somesub { local $foo = "Ovid"; anothersub(); } sub anothersub { print "\$foo is $foo\n"; }
This is mentioned primarily for the sake of completeness. Sometimes rules need to be broken.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Sharing a variable between subroutines
by tilly (Archbishop) on Jan 05, 2002 at 19:37 UTC |