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:
Abigail
Date:
February 15, 2008 14:40
Subject:
Re: [PATCH t/op/pat.t] Re: Change 33313 causing failures
Message ID:
20080215224038.GA500@abigail.be
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

No. A couple of points:

  - Regexp modifiers go *after* the regexp, not before.
  - Allowable modifiers are i, m, s, x, g, c, p, o.
  - ~ is unary operator (bitwise negation)
  - /pattern/ not bound with =~ matches against $_.

So you have the equivalent of:

  my $r = $_ =~ /(?<D>(?<A>foo)\s+(?<B>bar)?\s+(?<C>baz))/;
  my $s = ~$r;



But what I don't understand:

  $_ = "abc";

  say ~0;              #  18446744073709551614
  say ~"";             #  empty string.
  say /x/;             #  empty string (none matching regexp returns "")
  say scalar (/x/);    #  empty string (none matching regexp returns "")
  say ~/x/;            #  18446744073709551614


The latter, I do not understand. If /x/ returns the empty string, and
the bitwise negation of an empty string is an empty string, why is 
~/x/ equal to ~0?


Abigail

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