Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: why the output is not my expected?

by choroba (Cardinal)
on Mar 31, 2017 at 07:13 UTC ( [id://1186593]=note: print w/replies, xml ) Need Help??


in reply to why the output is not my expected?

List is not array. Read about the Comma Operator in the documentation.

In scalar context it evaluates its left argument, throws that value away, then evaluates its right argument and returns that value.

To get your expected output, you have to create an array:

sub find_chores { return my @arr = (8, 456, 310); }

or, if you don't want to name it:

sub find_chores { return @{ [ 8, 456, 310 ] } }

Update: there are more than two ways how to create an array:

sub find_chores { return map $_, 8, 456, 310; }

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: why the output is not my expected?
by zhenyisong (Initiate) on Mar 31, 2017 at 07:34 UTC
    Thanks,@choroba. I did not notice the difference between array and list.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found