well, the abs() call is only there for the case of -1 -- you can take it out to compare against your case, or put some other check in to your case such that -1 == $count behaves the same as 1 == $count. otherwise you're comparing apples & oranges.

also, my snippet used two interpolations where yours reduced it to one ($noun versus the constant iteration) which doesn't make a huge difference, but again, them citrus fruits... time for me to run home. if you haven't rebenched, I'll set one up that's as parallel as possible except for x vs. ?:

ps: I don't know how the x operator is implemented, which is why i said "theoretically" faster -- as far as i can tell, there is no need for it to include a branch.

UP-dilly-DATE : OK, i didn't do it last night, but I did it. I made this small change:

sub sub1() { for my $count (0..2) { my $declension = 's' x ($count != 1); my $result = sprintf "$count iteration$declension so far...\n" +; } }

and got ... actually, quite similar results:

timethis 2000000: 52 wallclock secs (26.95 usr + 0.39 sys = 27.34 CPU +) @ 73152.89/s (n=2000000) timethis 2000000: 38 wallclock secs (25.47 usr + 0.34 sys = 25.81 CPU +) @ 77489.35/s (n=2000000)

Which is interesting, to me.


In reply to Rex4: pluralization by Vynce
in thread pluralization by Vynce

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.