The problem is, the scalar of an array IS just a plain old scalar. You can't expect to tell the difference between the size of an array (such as '3'), and a plain old number (such as '3'). And your function really shouldn't care how the caller came up with the parameter it passed you.

If you expect an integer from 1 to 5, and you are passed the scalar of an array that happens to have between 1 and 5 elements, that is hardly wrong. It may just be a fancy way of counting widgets.

use strict; use warnings; use Carp; use constant BAR => 3.14159265; my @list = ('p','i','e'); taster(BAR); taster(22/7); taster("constant"); taster(\@list); taster(@list); taster(scalar @list); sub taster { my $p1 = shift; carp "Hey, that's too many parameters!" if @_; print "Ref of $p1 is '".(ref $p1)."'\n"; }
Gives
Ref of 3.14159265 is '' Ref of 3.14285714285714 is '' Ref of constant is '' Ref of ARRAY(0x182af0c) is 'ARRAY' Hey, that's too many parameters! at test.pl line 18 main::taster('p', 'i', 'e') called at test.pl line 12 Ref of p is '' Ref of 3 is ''

In reply to Re^5: Prototype for constant items??? by SuicideJunkie
in thread Prototype for constant items??? by LanX

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.