Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - tests - 5.20 "hash slices"
  • Loading branch information
fglock committed May 28, 2014
1 parent 1060d42 commit 4de7011
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions t5/01-perlito/530-hash-slice.t
@@ -0,0 +1,31 @@
use v5;
use strict;
use feature 'say';

say '1..2';

my %hash_slice;
my $res;

# http://perltricks.com/article/92/2014/5/27/Perl-v5-20-what-you-need-to-know

my %raindrops = ( splish => 4, splash => 9, splosh => 7 );
%hash_slice = %raindrops{ 'splish', 'splosh'};
# hash_slice is (splish => 4, splosh => 7)

$res = "@{[ %hash_slice ]}";
print 'not '
if $res ne 'splish 4 splosh 7'
&& $res ne 'splosh 7 splish 4';
say "ok 1 - hash_slice # $res";

my @raindrop_types = qw/splish splash splosh/;
%hash_slice = %raindrop_types[0, 2];
# hash_slice is (0 => 'splish', 2 => 'splosh')

$res = "@{[ %hash_slice ]}";
print 'not '
if $res ne '0 splish 2 splosh'
&& $res ne '2 splosh 0 splish';
say "ok 2 - hash_slice # $res";

0 comments on commit 4de7011

Please sign in to comment.