I'm off on a tangent of a tangent, not really solving a real problem, but I've come across this oddity and it's really bugging me. In each online example or tutorial for
pop() they always use a named array. Is it possible to not do that? Instead of this:
my @odds = (1,3,5,7,9);
print pop(@odds);
Is there a way to combine that onto one line? I've tried several variations, all of them generate an error, shown in the comments below the code:
use strict;
use warnings;
use v5.30;
#works
my @odds = (1,3,5,7,9);
print pop(@odds);
#9 (no error)
print pop((2,4,6));
# Experimental pop on scalar is now forbidden ... near "))"
print pop(@(2,4,6));
# Number found where operator expected ... near "@(2"
# (Missing operator before 2?)
# syntax error ... near "@(2"
print pop(@{2,4,6});
# Useless use of a constant (2) in void context ... line 19.
# Useless use of a constant (4) in void context ... line 19.
# Can't use string ("6") as an ARRAY ref while "strict refs" in use ..
+. line 19.
What's particularly curious is I know I've used the
@{} construct before to explicitly define an array, using XML::Simple.
$ErrorResponse = $xml->XMLin($objResponse->content, ForceArray => 1);
@Errors = @{$ErrorResponse->{Errors}};
I must be missing something, particularly in that first example:
print pop((2,4,6)); generates the error "Experimental pop on scalar is now forbidden". However,
(2,4,6) clearly isn't a scalar.