in reply to OO sub, hash or hash reference.

There's a few ways you could do it. I'd do it as such:
sub someMethod { my $self = shift; my $hashRef; if (UNIVERSAL::isa($_[0], 'HASH')) { $hashRef = shift; } else { $hashRef = { @_ }; } }
Of course, you can add more checks and lots of cool stuff. But, that's basically the idea.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: OO sub, hash or hash reference.
by dreadpiratepeter (Priest) on Feb 18, 2002 at 15:11 UTC
    Out of curiosity, why the isa instead of a ref($_[0]) eq 'HASH'?

    -pete
    Entropy is not what is used to be.
      after seeing the above code I did some reading:

      "The reason the original test is fragile ( ref($_[0]) eq 'HASH' ) is that it will make your code refuse to work on a hash if it happens to be blessed."

      It was simpler than I thought.