in reply to Re^5: Smart enough for Smart Match??? (was "Understanding ...Given/When" )
in thread Understanding the benefit of Given/When ...

But it is documented.

But when EXPR is one of the below exceptional cases, it is used directly as a boolean:

It makes sense. It allows

given ($x) { when (/abc/) { ... } when (/def/) { ... } when (/ghi/) { ... } }

to mean

if ($x =~ /abc/) { ... } elsif ($x =~ /def/) { ... } elsif ($x =~ /ghi/) { ... }

Replies are listed 'Best First'.
Re^7: Smart enough for Smart Match??? (was "Understanding ...Given/When" )
by LanX (Saint) on Mar 04, 2010 at 23:05 UTC
    What...

    OMG it took me a while to understand it ... yes it makes sense:

    use 5.010; use strict; use warnings; my @a=('abc'); given (@a) { print "$_\n"; when (/ARRAY/ ) { print "ARRAY\n" ;continue} # regex-match! when (/abc/ ) { print '/abc/'."\n" ;continue} # no match when (qr/abc/ ) { print 'qr/abc/'."\n" ;continue} # smart-match! }

    OUTPUT:

    ARRAY(0x8255a70) ARRAY qr/abc/

    Sigh ... do you agree that the docs could be more explicit? :)

    Cheers Rolf

      It's right after where it documents when($foo) is equivalent to when($_ ~~ $foo), and "/REGEX/" does appears. That's quite explicit.

      Now, maybe it could possibly be clearer. Documentation improvements are always welcome, especially from those who were confused by them. The latest version is available here. Submit a diff -u of your suggestion to perlbug@perl.org.