The only problem with using the magical goto is that for some reason it is incredibly slow.

If performance isn't an issue, then it's fine, but if performance is an issue avoid it like the plague:)

#! perl -slw use strict; use Benchmark qw[cmpthese]; sub recipe{ my @rice = @_; my $grains = scalar @rice; return $grains; +} sub curry { recipe( 'extra', @_) } sub spagetti { unshift @_, 'extra'; goto &recipe; } print recipe qw[1 2 3 4 5 6 7 8 9 0]; print curry qw[1 2 3 4 5 6 7 8 9 0]; print spagetti qw[1 2 3 4 5 6 7 8 9 0]; cmpthese( -10, { recipe => 'recipe qw[1 2 3 4 5 6 7 8 9 0];', curry => 'curry qw[1 2 3 4 5 6 7 8 9 0];', spagetti=> 'spagetti qw[1 2 3 4 5 6 7 8 9 0];', }); __END__ c:\test>225691 10 11 11 Benchmark: running curry, recipe, spagetti , each for at least 10 CPU seconds ... curry: 11 wallclock secs (10.41 usr + 0.00 sys = 10.41 CPU) @ 11 +838.29/s (n=123284) recipe: 10 wallclock secs (10.29 usr + 0.00 sys = 10.29 CPU) @ 15 +358.48/s (n=157962) spagetti: 9 wallclock secs (10.31 usr + 0.00 sys = 10.31 CPU) @ 75 +02.96/s (n=77393) Rate spagetti curry recipe spagetti 7503/s -- -37% -51% curry 11838/s 58% -- -23% recipe 15358/s 105% 30% -- c:\test>

Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.


In reply to Re: Re: subref with stored argument? by BrowserUk
in thread subref with stored argument? by Flame

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.