Can't give a good explanation, probably something to do with autovivifying
references or something, but if you predeclare the two functions, the code
runs as intended (I've added the two lines in below) ...
-kev
On Pungenday, the 38th day of Chaos, Gavin McCullagh squawked:
> Hi
>[liberal snipping]
>> #!/usr/bin/perl
>> use strict;
>
# Subroutine declarations.
sub shift2 (\@);
sub pop2 (\@);
>> my @friends = qw(Peter Paul Mary Jim Tim);
> (my $this,my $that) = shift2(@friends);
> # $this contains Peter, $that has Paul, and
> # @friends has Mary, Jim, and Tim
> print "$this | $that\n";
> print "@friends\n";
>> my @beverages = qw(Dew Jolt Cola Sprite Fresca);
> my @pair = pop2(@beverages);
>> # $pair[0] contains Sprite, $pair[1] has Fresca,
> # and @beverages has (Dew, Jolt, Cola)
> print "@pair\n";
> print "@beverages\n";
>>> sub shift2 (\@) {
> return splice(@{$_[0]}, 0, 2);
> }
>> sub pop2 (\@) {
> return splice(@{$_[0]}, -2);
> }
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!