in reply to Flattening out arguments to splice
#!/usr/bin/perl use 5.14.0; use strict; use warnings; sub my_splice_like_func { my ($list, $offset, $length) = @_; my @copy = @$list; return splice @copy, $offset // 0, $length // @copy - $offset; } $, = ' '; # just keepin' it pretty my $list = [qw< one two three four >]; say my_splice_like_func($list, 2); # want "three four"; get "two +three four" say my_splice_like_func($list, 2, -1); # want "three"; get "three fou +r"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Flattening out arguments to splice
by jwkrahn (Abbot) on May 30, 2018 at 00:34 UTC | |
by AnomalousMonk (Archbishop) on May 30, 2018 at 02:39 UTC | |
by AnomalousMonk (Archbishop) on May 30, 2018 at 01:58 UTC |