So, I wrote
to test my parameter. But, I got to thinking. What if it's not really an array, but a class that looks like an array, or a tie? Should I use isa instead?if (ref $value eq "ARRAY") {
If I eventually turn the range into a class by blessing the array reference and adding some members to, say, get the difference, then the isa would be handy. I think a tie would still test as an array.
But, in a related thought, I have some code that wants a number. Now, what if it's not really a number, but a 'bignum' class that overloads all the operators so it (mostly) can be used like a number? In this case, ideally I wouldn't care, because if it quacks like a duck it must be a duck. I want to test for the quack, not the duck. For $x+2 I don't care that $x is a class object not a scalar, but what about as an argument to pack? I suspect that would not work properly.
So, how much testing should one do to see if arguments are what are expected, and how does "overloading" functions to understand different data types complicate matters?
Any thoughts?
—John
In reply to if (ref $value eq "ARRAY") { by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |