Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my @arr = (1, 2, 3, 4, 5);
- # Pop from the rear.
- my $popped = @arr.pop;
- @arr.elems == 4 or die "Wrong length";
- $popped == 5 or die "Wrong value";
- # Push into the rear.
- @arr.push(99);
- @arr.elems == 5 or die "Wrong length";
- @arr[4] == 99 or die "Wrong value";
- # Shift from the front.
- my $shifted = @arr.shift;
- @arr.elems == 4 or die "Wrong length";
- $shifted == 1 or die "Wrong value";
- # Unshift into the front.
- @arr.unshift(100);
- @arr.elems == 5 or die "Wrong length";
- @arr[0] == 100 or die "Wrong value";
- # Splice out from arbitrary location.
- my @spliced = @arr.splice(1, 3, (20, 30, 40));
- @spliced ~~ (2, 3, 4) or die "Wrong array";
- @arr ~~ (100, 20, 30, 40, 99) or die "Wrong array";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement