use 5.010;
####
use feature 'switch';
##
##
no if $] >= 5.018, warnings => "experimental::feature_name";
##
##
no if $] >= 5.018, warnings => "experimental::switch";
##
##
Unknown warnings category 'experimental::switch' at ...
BEGIN failed--compilation aborted at ...
##
##
no if $] >= 5.018, warnings => "experimental::smartmatch";
##
##
given is experimental at ...
when is experimental at ...
when is experimental at ...
when is experimental at ...
##
##
#!/usr/bin/env perl -l
use 5.010;
use strict;
use warnings;
no if $] >= 5.018, warnings => "experimental::smartmatch";
print '*** test1() ***';
print "$_ is ", test1($_) for 0 .. 4;
print '*** test2() ***';
print "$_ is ", test2($_) for 0 .. 4;
print '*** test3() ***';
print "$_ is ", test3($_) for 0 .. 4;
sub test1 {
my ($var) = @_;
my $i;
given ($var) {
when (1) { $i = 'One' }
when (2) { $i = 'Two' }
when (3) { $i = 'Three' }
default { $i = 'Other' }
}
return $i;
}
sub test2 {
my ($var) = @_;
return $var == 1 ? 'One'
: $var == 2 ? 'Two'
: $var == 3 ? 'Three'
: 'Other';
}
sub test3 {
state $word_for = {qw{1 One 2 Two 3 Three}};
return $word_for->{+shift} || 'Other';
}
##
##
*** test1() ***
0 is Other
1 is One
2 is Two
3 is Three
4 is Other
*** test2() ***
0 is Other
1 is One
2 is Two
3 is Three
4 is Other
*** test3() ***
0 is Other
1 is One
2 is Two
3 is Three
4 is Other