Prototypes won't really help here. All they do is coerce the passed arguments into what you're expecting. You still have to document the API carefully so people are enlightened as much as possible. (I almost never use them.)

My point is that with using references directly, you'll get a better error message. If you're expecting an array reference and someone passes a hash reference, Perl will complain that you're doing arrayish operations on something that doesn't look like a hash. (If you're lucky, you won't get one of the obscure pseudohash errors...)

I'm not sure what you mean by figure out what type of variable a typeglob is aliasing to. You can use defined and exists on the typeglob slot to see if something's there and usable, but that has other subtleties and optimizations.

Checking the reference type with ref or UNIVERSAL::isa() is much better. It's much simpler.


In reply to Re: Re: Confused about typeglobs and references by chromatic
in thread Confused about typeglobs and references by Argel

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.