Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: how to get the String as regularexpression

by reneeb (Chaplain)
on Oct 03, 2006 at 14:20 UTC ( #576082=note: print w/ replies, xml ) Need Help??


in reply to how to get the String as regularexpression

Have a look at the qr-operator

sample:

#!/usr/bin/perl use strict; use warnings; my $extensions = qr/\.doc|\.gif/; my @files = qw(test.doc test.gif test.png test.jpg); for(@files){ if($_ =~ $extensions){ print "yes\n"; } }


Comment on Re: how to get the String as regularexpression
Select or Download Code
Replies are listed 'Best First'.
Re^2: how to get the String as regularexpression
by davorg (Chancellor) on Oct 03, 2006 at 14:43 UTC

    qr// doesn't change the way that the string is interpolated into a regex - it simply precompiles the string into a regex (see the documentation).

    Using qr// with the code from the original post won't fix the problem. You have fixed the problem by dropping the spurious '|' from the start of the regex.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-07-30 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls