# New Ticket Created by Ovid
# Please include the string: [perl #61772]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61772 >
sub array_normal (@array) {
say sprintf "Array has %d elements and the first value is '%s'",
@array.elems, @array[0];
return @array;
}
sub array_normal_copy (@array) {
say sprintf "Array has %d elements and the first value is '%s'",
@array.elems, @array[0];
return @array;
}
sub array_slurpy (*...@array) {
say sprintf "Array has %d elements and the first value is '%s'",
@array.elems, @array[0];
return @array;
}
sub array_slurpy_copy (*...@array is copy) {
say sprintf "Array has %d elements and the first value is '%s'",
@array.elems, @array[0];
return @array;
}
my @array = <a b c>;
my @new_array = array_normal(@array);
say @new_array[0];
@new_array = array_normal_copy(@array);
say @new_array[0];
@new_array = array_slurpy(@array);
say @new_array[0];
@new_array = array_slurpy_copy(@array);
say @new_array[0];
This outputs the following:
Array has 3 elements and the first value is 'a'
a
Array has 3 elements and the first value is 'a'
a
Array has 3 elements and the first value is 'a'
a
Array has 3 elements and the first value is 'a'
a b c
So the "*...@array is copy" behaves like the rest when in the sub, but when
returned, returns a single item.
Cheers.
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6