Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Your "code" to compare is inside double quotes so things like $_[0] are going to be interpolated in before the value is passed in to cmpthese. You'd want to use single quotes, or better provide a code ref.

sub cmpstr { my( $arg ) = @_; cmpthese( -2, 'string multiplier', sub { print strMulti( $arg ) }. 'string concat', sub { print strConcat( $arg ) }, ); }

That aside be aware that your two subs do different things; strConcat will return a single string consisting of three copies of the argument, while strMulti will return three copies of the argument as a list. I misread as pointed out below (I was seeing parens in there ($_[0])x3 that aren't there . . .).

Edit: Thirdly, don't prefix subroutine calls with an ampersand. There's rare corner cases where you need to do that (disabling prototypes) but in general it's unneeded and makes your code harder to read (and looks like you're still writing perl4).

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re: Did not work on benchmarking function with some non alphanumerics by Fletch
in thread Did not work on benchmarking function with some non alphanumerics by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-19 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found