cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
I have this code for a simplified illustration of the problem
Question is, how do I tell if the substitution matched anything? I thought I could check $&, but it's zero length every time through the loop. I don't understand why that is, because it's supposed to give the last successful pattern match, and there are successful matches in every case except the second.my @items = ('"Title Text Example"', 'Title Text Example', ' Title Tex +t Example ',' "Title Text Example"'); foreach my $title (@items) { $title =~ s/^\s*\"?|\"?\s*$//g; print length($&)," $title\n"; }
Steve
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Determing if this regex matched
by toolic (Bishop) on Aug 06, 2011 at 19:40 UTC | |
by cormanaz (Deacon) on Aug 06, 2011 at 19:57 UTC | |
by ww (Archbishop) on Aug 06, 2011 at 20:06 UTC | |
by cormanaz (Deacon) on Aug 06, 2011 at 20:34 UTC | |
by AnomalousMonk (Archbishop) on Aug 07, 2011 at 10:22 UTC | |
by merlyn (Sage) on Aug 06, 2011 at 20:12 UTC | |
by cormanaz (Deacon) on Aug 06, 2011 at 20:30 UTC | |
Re: Determing if this regex matched
by toolic (Bishop) on Aug 07, 2011 at 00:16 UTC |