Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Stop variable expansion

by GrandFather (Saint)
on Mar 19, 2021 at 03:38 UTC ( [id://11129943]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Stop variable expansion
in thread Stop variable expansion

looking at the solution there is no way I would have been able to work that one out

Of course there was a way - RTFM: read the fine manual. In fact both answers gave you the reference you needed: quotemeta. One of Perl's good points is comprehensive documentation. Sometimes it takes some digging, and it's harder if you don't know what you are looking for, but it's almost always there.

For future reference you can of course quote problematic strings (as already noted in earlier answers):

use strict; use warnings; my $Name = '[A'; my $SearchInHere = "FredJimBert[A"; print "Matched quoted\n" if $SearchInHere =~/\Q$Name\E/; print "Matched raw\n" if $SearchInHere =~/$Name/;

Prints:

Unmatched [ in regex; marked by <-- HERE in m/[ <-- HERE A/ at noname. +pl line 8. Matched quoted

Output order is backwards in time, but that's pretty normal for errors and warnings.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-25 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found