in reply to How to tell if I have a string, or a ref to a hash
The tools have been provided already, but I wanted to add a comment: You can't do it perfectly unless you disallow certain special cases related to overloading. Perl is designed around of the concept of implicit coercion, so trying to use type-based polymorphism in Perl is inherently flawed.
By the way, your use of a prototype is not only unnecessary, it's wrong. You tell Perl that the sub takes no arguments ("sub xyz()"), but the sub clearly does take arguments ("while(defined($arg = shift))") and you have to tell Perl to ignore the fact that you told it the sub takes no arguments ("&xyz"). You should have
sub xyz { ... } xyz($s); xyz(\%h);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to tell if I have a string, or a ref to a hash
by mshaw (Initiate) on Oct 19, 2010 at 18:06 UTC | |
by jakeease (Friar) on Oct 19, 2010 at 18:44 UTC |