Hello gregory-nisbet,
First, I don’t understand what you are trying to do. How does “pattern matching in languages like Haskell and OCaml” differ from Perl-style regular expressions work? Some explanation would be helpful here. At the very least, you should indicate the output you want to get from the call to match "bob", 45, sub { print $bob; }.
Second, the warning messages are telling you that the package-global variable $bob is being used without having been first initialised or even declared. A search through your code shows that $bob occurs once only, in the print statement within the anonymous subroutine passed to sub match. There is also the string, "bob", passed in to that subroutine, so I’m guessing you expect the variable to be somehow created, from the passed-in string, within that sub? It isn’t, and I don’t know why you think the while loop localisation you identify is relevant here?
Third, when you start sprinkling no strict 'refs' and no strict around your code to keep the compiler quiet, this is almost always a sign that your design is faulty.
Fourth, the use of prototypes in sub match ($$$) is probably a bad idea. Please study
Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen
and then restrict yourself to using prototypes in only those situations where the “implicit context coercion” (in Tom Christiansen’s phrase) which they provide is actually useful.
Update: Amended sentence re “pattern matching”. Thanks to LanX, below.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: rough approximation to pattern matching using local
by Athanasius
in thread rough approximation to pattern matching using local
by gregory-nisbet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |