First off, if you're asking a question like this, don't use prototypes. They're not required in Perl and they probably don't do what you're expecting - a Perl prototype isn't the same thing as a C prototype. See the example at the end of the perlsub section on prototypes and/or The purpose of prototypes in perl subroutines for more details.

Now, on to your actual question...

You can use ref to test whether your first argument is a scalar, a hashref, or an array ref to get some multi-style support, but, if the first argument is a scalar, you have no way to determine whether it's the first element of an array or the first key in a hash, since arrays and hashes are both passed in as plain lists. (I suppose you could test the size of @_, which would tell you it's an array if there are an odd number of elements, but you'd still just be taking a shot in the dark if it's even.)


In reply to Re: Function that accepts both hashes/arrays and hashrefs/arreyrefs by dsheroh
in thread Function that accepts both hashes/arrays and hashrefs/arreyrefs by pshangov

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.