regex - perl $ anchor failed to match end of line -
example: my $pattern = "mkdir &"
as can see, patterns commands , want pattern match "&+eol" distinguish whether command runs on background or not.
i tried /&$/, /&\$/ failed.
what wrong? suggestion pattern match?
45: if ($command =~ /&$/) {
db<2> p $command
mkdir &
db<3> s
54: print $_;print "\n";
your pattern works fine
use strict; use warnings 'all'; use feature 'say'; $pattern = 'mkdir &'; $pattern =~ /&$/ ? 'match' : 'no match'; output
match it impossible tell question, have whitespace @ end of string trying match. perhaps have space or linefeed there, or perhaps processing file has originated on windows , have removed lf, leaving terminating cr.
you can fix adding optional whitespace @ end of regex pattern, this
say $pattern =~ /&\s*$/ ? 'match' : 'no match'; you can see string contains using data::dumper, this
use data::dumper; $data::dumper::useqq = 1; print dumper $pattern; in instance produces $var1 = "mkdir &";, , able see if there superfluous characters after &.
Comments
Post a Comment