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.

In reply to passing an array without a name to pop() by TieUpYourCamel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.