Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

RE: Help using Benchmark.pm

by autark (Friar)
on Jul 12, 2000 at 23:02 UTC ( #22250=note: print w/replies, xml ) Need Help??


in reply to Help using Benchmark.pm

Hi,

Your problem can be solved by making $myvar a global, either by using:

use vars qw|$myvar|; $myvar = "...";
or if you use perl 5.6:
our $myvar = "...";
It can also be solved by letting the keys in that hash point to functions:
timethese(100000, { Greedy => sub { $myvar =~ /"(.*)"/ }, Lazy => sub { $myvar =~ /"(.*?)"/ }, Negated => sub { $myvar =~ /"[^"]*"/ } });
If the value of one of the keys is not a reference to a function, Benchmark is forced to eval your code - and when you eval a string all the variables referenced within it will be looked up in the stash (where all the symbols live) - they are treated as globals you could say. That's why it works when you make $myvar a non-lexical variable.

Autark.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-11-27 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?