@ikegami, I believe you've mistaken bichonfrise74 and myself as being the same person, however it seems they've simply stumbled across this thread and wanted some clarification on how perl's prototypes work.

I would like to note, though, that I made some hasty last-minute changes to that subroutine before posting in an attempt to trim it down to only the code that I felt was relevant to the issue at hand. Unfortunately I neglected to remove the $self initialization at the top of the subroutine, which seems to have caused some confusion.

@bichonfrise74, I'm rather new to perl, myself, but I did some digging and it seems that the prototypes don't necessarily enforce constraints on subroutine arguments, rather they coerce the arguments that are passed into the variable types listed in the prototype. At least, that's the impression I got from http://www.perlfoundation.org/perl5/index.cgi?prototype

Update: Seems I was a little hasty in my interpretation. "Coerced" isn't necessarily the correct word there, as it implies the variable's value would remain yet be offered in a new context. Instead, the arguments are interpreted by the subroutine as being in the context of the prototype, meaning if an @array is passed where a $scalar is expected, what would result is actually the length of that array, since $scalar = @array assigns the length of @array to @scalar.

I hope that's clearer, my apologies for any misunderstandings.


In reply to Re^4: Using s/// Inline by Jason Hutchinson
in thread Using s/// Inline by Jason Hutchinson

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.