in reply to Appending backslash to a string
If you want to include a variable inside a regex, but don't want the data in the variable treated as part of the regex then you wrap it in \Q \E (which i beleve stand for quote and end, its at least how i rememebr)
#!/usr/bin/perl use strict; use warnings; my $char = '\\'; my $str = 'bla'; $str =~ s/\Q$char\E?$/$char/; print "$str\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Appending backslash to a string
by wind (Priest) on Aug 11, 2007 at 00:31 UTC | |
|
Re^2: Appending backslash to a string
by garu (Scribe) on Aug 11, 2007 at 00:56 UTC | |
|
Re^2: Appending backslash to a string
by ThomMerton2242 (Initiate) on Jun 29, 2020 at 13:37 UTC | |
by haukex (Archbishop) on Jun 29, 2020 at 14:49 UTC | |
by hippo (Archbishop) on Jun 29, 2020 at 15:46 UTC |