Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How to express contents of a file as regex metachars?

by jwkrahn (Monsignor)
on Jun 16, 2012 at 05:54 UTC ( #976532=note: print w/ replies, xml ) Need Help??


in reply to How to express contents of a file as regex metachars?

if ($data =~ /^([\d\w]+)/ ) { notate('A', length($1)); }

Your use of [\d\w] is redundant because the \w character class also includes the same characters of the \d character class.    Also, the \w character class includes the _ character (underscore) which is not an alphanumeric character.    You should just use [A-Za-z0-9] which only matches alphanumeric characters.

You don't have to capture the match and get its length, you can just pass its length directly:

if ($data =~ /^[A-Za-z0-9]+/ ) { notate('A', $+[0]); }


Comment on Re: How to express contents of a file as regex metachars?
Select or Download Code
Re^2: How to express contents of a file as regex metachars?
by dwhite20899 (Friar) on Jun 16, 2012 at 19:49 UTC
    Argh - I'm an idiot, I should have known \w wasn't correct. And I didn't know (or completely forgot) about $+ so thanks for that tip!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-09-16 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls