develooper Front page | perl.perl5.porters | Postings from February 2008

Re: [PATCH t/op/pat.t] Re: Change 33313 causing failures

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
February 15, 2008 14:28
Subject:
Re: [PATCH t/op/pat.t] Re: Change 33313 causing failures
Message ID:
20080215222845.GD46892@penkwe.pair.com
On Fri, Feb 15, 2008 at 05:04:26PM -0500, Matthew Persico wrote:
> On Feb 15, 2008 6:03 AM, Abigail <abigail@abigail.be> wrote:
> > On Thu, Feb 14, 2008 at 02:17:57PM -0500, Jerry D. Hedden wrote:
> [snip-age throughout]
> > There's a typo that causes havoc. Here's a fix.
> >
> > -    if ($s = ~/(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/) {
> > +    if ($s =~ /(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/) {
> 
> In an effort to understand, I digress:
> 
> In the line that was in error what the heck got assigned to $s? As I
> understand it, the only modifiers that are allowed in front of a RE
> are i,m,s or x so shouldn't a syntax error have been thrown? Under
> perl 5.10.0:
> 
> $  perl -e '
> > $s=0;
> >  $s = ~/(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/;
> > print $s;'
> 4294967295

~ is the unary bitwise negation operator.  A regex match that's not bound
to a specific string is matched against $_.  Not surprisingly,
/(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/ did not match against $_.  $s,
therefore, was assigned the value ~0.

Regex modifiers, by the way, go after the regular expression, not before.

Ronald

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About