Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Strange behavior of array in scalar context

by Anonymous Monk
on Jan 27, 2026 at 14:50 UTC ( [id://11167247]=note: print w/replies, xml ) Need Help??


in reply to Strange behavior of array in scalar context

my @executions = $jobInfo->{'content'}{'executions'};

This puts whatever happens to be returned on the right-hand side into the first slot of the array @executions. It just happens that what you get is from the RHS not an empty array, but an empty arrayref. And this arrayref happens to occupy the first slot of the array @executions. Therefore, the array @executions has one element.

See what print Dumper \@executions; returns instead.

To turn an arrayref into an array (i.e. copy its contents to an array), you need to dereference it, or you can just keep using it as an arrayref. I usually do the latter.

# Dereference and copy contents my @executions = @{ $jobInfo->{'content'}{'executions'} }; # Just use it as an arrayref my $executions = $jobInfo->{'content'}{'executions'}; print scalar @$executions, "\n"; print "element 0 is ", $executions->[0], "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11167247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2026-04-21 06:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.