in reply to generating subroutines from array variables

Although I really like the AUTOLOAD approach, I've used a different method in the past.

WARNING: The following code could cause nasty personal side effects, not limited to people running when they see you.

my @tags= qw/name gender address/; foreach my $t (@tags) { eval "sub $t { \$state{'$name'} = 1; }"; eval "sub ${t}_ { \$state{'$name'} = 1; }"; }

Of course, if you find that one too disgusting. You could always run a loop once to write the appropriate code to a Perl module file and then use that file.

BEGIN { unless(-e "Tags.pm") { my @tags= qw/name gender address/; open( F, ">Tags.pm" ) or die "Unable to create Tags.pm:$!"; foreach my $t (@tags) { print F "sub $t { \$state{'$name'} = 1; }\n"; print F "sub ${t}_ { \$state{'$name'} = 1; }\n"; } print F "1;\n"; close( F ) or die "Unable to close Tags.pm:$!"; } } use Tags;

Ain't code that writes code a wonderful thing.

Update: I forgot to add the "1;" at the end.

G. Wade