note
almut
<p> I <i>think</i> the OP is essentially asking ([Sixtease] please
correct me if I'm wrong) how you would make something like the
following snippet print "e", and not "2" </p>
<c>
my @x = qw(a b c);
my @y = qw(d e);
print scalar (@x, @y); # prints "2" (number of elems in @y)
</c>
<p> treating the combined arrays as if they had been written like </p>
<c>
print scalar qw(a b c d e); # prints "e" (last elem in list)
</c>
<p> Kind of like this </p>
<c>
print scalar ((@x, @y)[0..@x+@y-1]); # prints "e"
print scalar sub {@_[0..$#_]}->(@x, @y); # prints "e"
</c>
<p> but less ugly, and without having to take special care of the
subtle problem you run into with older versions of Perl when the
arrays are empty, and the selecting range for the slice becomes
<c>[0..-1]</c> (what this thread is about, essentially). </p>
<p> Irrespective of whether you'd actually <i>need</i> to do something like
this in real-life programming, it's still a valid question in and of
itself, IMO. </p>
663945
664213