On Apr 16, 2004, at 7:15 AM, Joel Rees wrote:

slice syntax isn't deprecated or anything is it? Don't see it mentioned in O'Reilly's Nutshell or in the Cookbook's section on arrays.

There is no "slice" function. You can use the splice function, but this syntax is easier:


my @foo = qw(one two three four);
my @slice = @foo[1,3]; # (one, three)

Do it with array references like this:

my $ref = [EMAIL PROTECTED];
@slice = @{$ref}[2,4]; # (two, four)

You can also slice hashes:

my %bar = (one => 1, two => 2, three => 3, four => 4);
@slice = @bar{qw(one four)}; # (1, 4)

And hash references:

$ref = \%bar;
@slice = @{$ref}{qw(two four)}; # (2, 4)

HTH,

David (Who doesn't consider this off-topic)



Reply via email to