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

Re: Perl treats period as space in string

by perlfan (Vicar)
on Jul 20, 2021 at 22:07 UTC ( [id://11135238]=note: print w/replies, xml ) Need Help??


in reply to Perl treats period as space in string

It's confusing to define the regexp in a variable, then place it there between the /../; The reason is that in the assignment it's very much just a string. When you place it in the regexp context, it suddenly means something different (i.e., the "dot"). So don't do that unless it's very cleary you're dynamically defining your regular expression, otherwise you're just making it more confusing for you and anyone else who may be looking at this even in the very near future.

Replies are listed 'Best First'.
Re^2: Perl treats period as space in string
by BillKSmith (Monsignor) on Jul 21, 2021 at 18:49 UTC
    You can solve this problem with qr in Regexp Quote Like Operators.
    use strict; use warnings; use Test::More tests => 2; my $phrase = qr/club\.market/; unlike( 'club market', $phrase, 'not match space' ); like( 'club.market', $phrase, 'match period' );

    RESULT,

    1..2 ok 1 - not match space ok 2 - match period
    Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found