Struppi: s/../.. - Variableninterpolation

Beitrag lesen

Hi zusammen,

ich will den Inhalt der Variable bei einer Substitions druch "nichts"
ersetzen.

Meine Variable:
my $quelle = "D:\Proggen\Perl\Projekte\me-spiegel\sp";

Meine Substitution:
($relativer_pfad=$pfad_dos)=~ s/$quelle//g;

Folgende Fehlermeldung:
Unrecognized escape \m passed through in regex; marked by <-- HERE in m/D:\Proggen\Perl\Projekte\m <-- HERE e-spiegel\sp/ at
me-spiegel\me-spiegel.pl line 31.

Ich bin mir jetzt nich ganz sicher, aber ich glaube du suchst:
    \Q          quote (disable) pattern metacharacters till \E

If use locale is in effect, the case map used by \l, \L, \u and \U is taken from the current locale. See the perllocale manpage. For documentation of \N{name}, see the charnames manpage.

You cannot include a literal $ or @ within a \Q sequence. An unescaped $ or @ interpolates the corresponding variable, while escaping will cause the literal string $ to be matched. You'll need to write something like m/\Quser\E@\Qhost/.

Wobei ich das so verstehe, das du den String von Hand escapen musst, evtl. mit sowas:
$quelle =~ s/\/\\/g;

Struppi.

P.S.: kann aber auch Quatsch sein, hab grad keine Lust das testen.