What's going on here?

Christopher Shannon cshannon at mdo.net
Sun Sep 19 22:11:35 CDT 1999


I've just written a module which generates a hash of anonymous subroutines,
which test whether or not a number inputed by the user is valid against a
certain mask.

This mask is effected by a regex in each subroutine.

However, I have found that when the anonymous subs are called after a regex
in the main program has been executed, it acts funny and gives unexpected

You can test to see what I mean in the file 15.pl:

copy all the attached files in the same directory and at
the prompt in the directory, type

                                            15.pl blah number

And the prompts should be self explanatory. If you input either a 1 or 2
digit number (in place of 'blah'), or a Perl scalar $any_var1, etc., then
the subroutine will return the number you type and it will be printed, and
the program will exit.  The last parameter, (number) points to a particular
mask in the hash reference; you can use 'boolean', 'name', etc., if you want
to experiment with it.

The problem comes when you remove the # at lines 10 and 11, and try to run
the program, it does not work properly.  It returns whatever you input
without bothering to check it with the regex.  In line 11, if you substitute
a value which the regex does not find, then the anonymous subroutine will

I would like to be able to use this array of anonymous subroutines anywhere
in any code, but it seems that the regexes of the main program do funny
things to the regexes of the anonymous subroutines.

Is there some workaround for this?

Thanks in advance, regards, Chris S.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 15.pl
Type: application/octet-stream
Size: 169 bytes
Desc: not available
Url : http://mail.pm.org/archives/baltimore-pm/attachments/19990919/f1f19c79/15.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VCode.pm
Type: application/octet-stream
Size: 1416 bytes
Desc: not available
Url : http://mail.pm.org/archives/baltimore-pm/attachments/19990919/f1f19c79/VCode.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: input.msk
Type: application/octet-stream
Size: 614 bytes
Desc: not available
Url : http://mail.pm.org/archives/baltimore-pm/attachments/19990919/f1f19c79/input.obj

More information about the Baltimore-pm mailing list