in reply to Re: Passing a database connection
in thread Passing a database connection
my @x = 0 .. 9; print "@x[2..4]\n"; print "@x[3,5,7]\n"; my @y = 4..6; print "@x[@y]\n"; @x[7..9] = @y; print "@x\n";
The reason why you don't want to use the arrayslice form when you want to extract a single element is, while it has been special-cased to work in the case of my $x = @x[2]; (it should assign 1 and not 2), it won't work in this case:
@x[2] is list context, not scalar context.sub foo { wantarray ? 3 : 5; } my @x; @x[2] = foo(); my $x = foo(); print "$x[2] <-> $x\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Passing a database connection
by doob (Pilgrim) on Nov 23, 2005 at 19:24 UTC |