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.
In reply to Re^3: Stop variable expansion
by GrandFather
in thread Stop variable expansion
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |