Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
mirod said:
Can't you just use any character (here the space) to delimit a regexp?
That's not happening here:
print "Good\n" if $test =~ ab;
There is no space to the right of the regex. If anything, it would be a word boundary as the delimeter (\b in a regex). This appears to be, as merlyn mentioned, a bareword being promoted to a string and then to a regex.

mirod said:

This code actually does not pass -w and use strict on my Solaris/Perl 5.6 combo.

Are you sure ab is not pre-compiled or some similar trickery?

Nope, it's not precompiled. I just got home (I'm home early due to being sick as a dog. Don't lick my posts, I wouldn't want you to get ill) and tried it on my Win98 box and again, it runs fine.

Naturally, I'm curious as to the performance aspects, so I decided to benchmark this.

#!/usr/bin/perl -w use strict; use Benchmark; my $test; #print "Good\n" if $test =~ ab; timethese(-15, { bare => '$test = "aba"; $test =~ ab', delimited => '$test = "aba"; $test =~ /ab/' });
Whups! All of a sudden, I get a whole slew of messages like the following:
Unquoted string "ab" may clash with future reserved word at (eval 1) l +ine 1.
Somehow, eval is catching the problem. By removing the -w switch, the code ran fine (but still works with strict, go figure).

Incidentally, the benchmark results showed no significant performance impact:

Benchmark: running bare, delimited, each for at least 15 CPU seconds.. +. bare: 13 wallclock secs (15.01 usr + 0.00 sys = 15.01 CPU) @ 45 +7834.84/s (n=6872101) delimited: 16 wallclock secs (15.00 usr + 0.00 sys = 15.00 CPU) @ 45 +8124.53/s (n=6871868)
I want to explore this more and see just how complicated of a regex I can make here, but I need to get some sleep.


Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

In reply to (Ovid - benchmarking a bare regex) RE: Odd... by Ovid
in thread Odd... by Ovid

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-01-23 12:05 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.