Skip to content

Commit a0beddf

Browse files
committed
Perlito5 - tests - slice tricks
1 parent 9643c62 commit a0beddf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

t5/01-perlito/080-array.t

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use v5;
22
use strict;
33
use feature 'say';
44

5-
say '1..26';
5+
say '1..27';
66
my @a;
77
say 'ok 1 - create array';
88
$a[1] = 3;
@@ -143,3 +143,16 @@ print "not "
143143
unless $v eq "[9 8 7]";
144144
say "ok 26 - hash slice assignment # $v";
145145

146+
147+
# from http://perltraining.com.au/tips/2009-03-11.html
148+
my @duplicates = (1, 1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 9, 2, 3, 3,);
149+
my %unique;
150+
# Our hash here has keys, but all its values will be undefined.
151+
# That's fine, since we're only interested in the keys.
152+
@unique{@duplicates} = ();
153+
my @unique_elements = sort keys %unique;
154+
$v = "@unique_elements";
155+
print "not "
156+
unless $v eq '1 2 3 4 5 6 7 8 9';
157+
print "ok 27 - unique_elements $v\n";
158+

0 commit comments

Comments
 (0)