in reply to generating subroutines from array variables
my @list = qw/foo bar baz/; foreach my $element (@list) { *{$element} = sub { $state{$element} = 1; }; *{"${element}_"} = sub { $state{$element} = 0; }; }
If you are using strict {insert standard admonition here} you'd need to use:
in the loop, I believe.no strict 'refs';
On another note, without knowing just what your goal is, there is likely another XML module that might do more of what you need for you. A search at search.cpan.org for "XML" returns over 2000 matches. :)
UPDATE: Added the missing semi-colons. Thanks to esh for pointing out they were missing. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: generating subroutines from array variables
by esh (Pilgrim) on Aug 17, 2003 at 17:16 UTC |