in reply to How can I differentiate between 0 and whitespace in Perl?

use feature ":5.10"; $val=" "; given($val) { when (" ") { print "space"} when (0) { print "zero"} default { print "other" } }

print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Replies are listed 'Best First'.
Re^2: How can I differentiate between 0 and whitespace in Perl?
by almut (Canon) on Apr 19, 2009 at 11:40 UTC

    Side note:  I'd use 5.010; instead of use feature ":5.10";.  The net effect is the same, but the innocent/inexperienced user of an older version of Perl will probably appreciate a clear message indicating what the problem is, i.e.

    $ perl -M5.010 -e1 Perl v5.10.0 required--this is only v5.8.8, stopped at ... vs. $ perl -Mfeature=:5.10 -e1 Can't locate feature.pm in @INC (@INC contains: ...

    with no mention of 5.10 in the latter.

      Then this should be fixed in perlsyn, because use feature ":5.10" is what you find there. *sigh* The 5.10 vs. 5.010 syntax is nasty.

      print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
      Then they'll comment out #use 5.010; and be equally confused ;)

        yeah, but it's their problem then, not the script/module author's — they're no longer innocent in this case... :)