Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Did not work on benchmarking function with some non alphanumerics

by Fletch (Bishop)
on Jan 15, 2022 at 00:04 UTC ( [id://11140458]=note: print w/replies, xml ) Need Help??


in reply to Did not work on benchmarking function with some non alphanumerics

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.

Replies are listed 'Best First'.
Re^2: Did not work on benchmarking function with some non alphanumerics
by jwkrahn (Abbot) on Jan 15, 2022 at 05:16 UTC
    while strMulti will return three copies of the argument as a list.

    SCALAR x 3 will return a scalar while LIST x 3 will return a list.

    So the two subs do basicaly the same thing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140458]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found