9. ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
CATCH {
default { put "Caught something" }
}
my $fh = open 'not-there'; # this fails
put "Result is " ~ $fh.^name;
unless $fh { # $fh.so
given $fh.exception {
put "failure: {.^name}: {.message}";
}
}
Result is Failure
failure: X::AdHoc: Failed to open file
14. ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my $scalar = 'Hamadryas';
my @array = qw/ Dog Cat Bird /;
my %hash = a => 1, b => 2, c => 3;
put "scalar: $scalar";
put "array: @array[]";
put "hash: %hash{}";
scalar: Hamadryas
array: Dog Cat Bird
hash: a 1
b 2
c 3
28. ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @f = @ab;
@f = slippery( @f );
sub slippery ( $l, $level = 0 ) {
put "t" x $level, "Got ", $l;
my @F;
for $l.list {
when .elems == 1 { push @F, $_ }
default {
push @F, slippery($_,$level + 1 ) }
}
@F.Slip;
}
( a b c d e f a b c x y z w )