Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: ATC på 27. ſeptember 2008, 18:24 pm

Tittel: How to get a slice of an array in Perl
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
The Perl language includes the splice() function, which upon returning a subset of records from an array (a slice) removes those records from the original array. But it does not include a slice() function. "Programming Perl" describes a slow way to do it.
Tittel: [Solved] How to get a slice of an array in Perl
Skrevet av: ATC27. ſeptember 2008, 18:24 pm
Here's a faster one, although it does use more memory:

sub slice
{
  my (@array) = @_;
  my $count = pop @array;
  my $offset = pop @array;
  return splice(@array, $offset, $count);
}