Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Are these equal? (Score:2, Interesting)

    Looking at An Aside: the "Smart Match" Operator on page 3, are these equal?

    ($elem =~ @array) == (@array =~ $elem)

    ($key =~ %hash) == (%hash =~ $key)

    ($value =~ (1..10)) == ((1..10) =~ $value)

    ($value =~ ('a', /\s/, 7)) == (('a', /\s/, 7) =~ $value)
    • Yes.

      Larry
      • by hossman (2110) on 2002.04.06 15:34 (#6697)
        Are you saying that the =~ is going to be defined such that ($paco =~ $yakko) == ($paco =~ $yakko) will allways be true? (or are you saying that just the 4 examples $Bob listed will allways be true)

        What if $paco and $yakko are both sub refs? there's no garuntee that $yakko.($paco) will ever be equal to $paco.($yakko).

        for that matter, what about the list behavior Damian describes...

        if $value =~ ('a',/\s/,7) {...}
        # true if $value is eq to 'a'
        # or if $value contains whitespace
        # or if $value is == to 7

        That final example illustrates some of the extra intelligence that Perl 6's =~ has: When one of its arguments is a list (not an array), the "smart match" operator recursively "smart matches" each element and ORs the results together, short-circuiting if possible.

        What happens in this scenerio...

        if ($sub1 =~ ($sub2, $sub3)) { ... }

        is it equivilent to ($sub1.($sub2) || $sub1.($sub3)) ? Or ($sub2.($sub1) || $sub3.($sub1)) ?

        • Are you saying that the =~ is going to be defined such that ($paco =~ $yakko) == ($paco =~ $yakko) will allways be true? (or are you saying that just the 4 examples $Bob listed will allways be true)

          He's saying the latter. The matching rules are supposed to be "sensible" and "reasonable" (for sufficiently vague values of those two words ;-)

          The table in A4 [perl.com] lists the behaviours of =~ under various combinations of arguments.

          What if $paco and $yakko are both sub refs? there's no garuntee that $yakk