If you already have all of the data in memory it doesn't do much good to keep passing it out piecemeal like that. If you were reading from a file, you could use your function to read a single line and return an array of each split piece of that line in a fashion similer to fetchrow. If you really do want to pass out pieces of a pre-existing array like that, though, you can do it like this:
my @array = ([1, 2, 3], [4, 5, 6], [7, 8, 9]);
# non-destructive
my $index = 0;
sub nextitem {
return if $index > $#array;
return @{$array[$index++]};
}
# more elegant, but destroys @array
sub nextitem {
return unless @array;
return @{shift(@array)};
}
Is this what you meant?