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

smart-match (un)commutability

Thread Next
From:
Tom Christiansen
Date:
February 26, 2011 09:10
Subject:
smart-match (un)commutability
Message ID:
19586.1298740202@chthon
In 5.10, these both returned true:

    %ENV   ~~ "TERM"
    "TERM" ~~ %ENV 

but by 5.11, the first of those fails because commutabilty 
of the smart-match operator was rescinded.  While it's true 
that you can do either of these:

    "TERM" ~~ %ENV 
    %ENV   ~~ ["TERM"]

instead of the now non-working:

    %ENV   ~~ "TERM"

It also means you can't do this anymore:

    given(%Opts) {
        when ( "fullpaths" )    {  }
        when ( "shortpatsh" )   {  }
        when ( "nopaths" )      {  }
        when ( "dospaths" )     {  }
    } 

but rather must do this:

    given(%Opts) {
        when (["fullpaths"])    {  }
        when (["shortpatsh"])   {  }
        when (["nopaths"])      {  }
        when (["dospaths"])     {  }
    } 

Is that accurate?  

And what does (HASH ~~ SCALAR)  mean?  The table in perlop^H^Hsyn
doesn't even mention it:

   $a      $b        Type of Match Implied    Matching Code
   ======  =====     =====================    =============
   Hash    CodeRef   sub truth for each key[1] !grep { !$b->($_) } keys %$a
   Hash    Hash      hash keys identical (every key is found in both hashes)
   Hash    Array     hash keys intersection   grep { exists $a->{$_} } @$b
   Hash    Regex     hash key grep            grep /$b/, keys %$a

--tom

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