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

OK, so I didn't know how to replace the "rogue" characters with escaped versions, and looking at the solution there is no way I would have been able to work that one out !!! :) Indexing I think is the right solution and better matches the intent, i.e. find 'this' in 'that'. Thanks for taking the time to reply and help. Very much appreciated. BR, Steve

Replies are listed 'Best First'.
Re^3: Stop variable expansion
by GrandFather (Saint) on Mar 19, 2021 at 03:38 UTC
    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