Think about Loose Coupling | |
PerlMonks |
Re: rough approximation to pattern matching using localby Athanasius (Archbishop) |
on Jan 25, 2015 at 06:51 UTC ( [id://1114416]=note: print w/replies, xml ) | Need Help?? |
Hello gregory-nisbet, First, I don’t understand what you are trying to do. How does “pattern matching in languages like Haskell and OCaml” 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,
In Section
Seekers of Perl Wisdom
|
|