问题
I'm not exactly a perl monk, so if you could help me digest what does this regex(if it is one) do?
my $pathHere = "/some/path/to/file";
my $pathThere = "/some/path/";
$pathHere =~ s|$pathThere||;
Perl is not exactly my everyday tool, so I am quite shy on knowledge - I guess it subs the match to the var value, but guessing is not the way to go - the pipes throw me off...
Thanks
回答1:
In Perl you'd normally use the / as a delimiter in the regexp.
$pathHere =~ s/abc/def/; # replace 'abc' with 'def'
However you can see that for paths, that's problematic, since you'd have to escape everything.
$pathHere =~ s/my\/path\/here/my\/newpath\/there/;
Consequently Perl allows you to specify a different delimiter as the character after the 's', hence:
$pathHere =~ s|my/path/here|my/newpath/there|;
See the documentation for more information.
来源:https://stackoverflow.com/questions/31830613/perl-regex-with-pipes