Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6850565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:08:25+00:00 2026-05-27T01:08:25+00:00

my $mind = ( ‘a’, ‘little’, ‘confused’ ); And it’s because perldoc perlfaq4 explains

  • 0
my $mind = ( 'a', 'little', 'confused' );

And it’s because perldoc perlfaq4 explains the line above as follows (emphasis added):

Since you’re assigning to a scalar, the righthand side is in scalar
context. The comma operator (yes, it’s an operator!) in scalar context
evaluates its lefthand side, throws away the result, and evaluates
it’s righthand side and returns the result. In effect, that
list-lookalike assigns to $scalar it’s rightmost value. Many people
mess this up because they choose a list-lookalike whose last element
is also the count they expect:

my $scalar = ( 1, 2, 3 );  # $scalar gets 3, accidentally

What I understand this to mean is that there is no such thing as a list in scalar context.

However, ikegami maintains that it “result[s] in a list operator, so it is a list literal.”

So, is it a list or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:08:25+00:00Added an answer on May 27, 2026 at 1:08 am

    A list literal is something that is actually a list written out in code, so (1, 2, 3) is a list literal, whereas caller for example is a function that could return a list or a scalar depending on context.

    In a line like:

    my $x = ...;
    

    the ... sees scalar context, so if ... was a list literal, then you would have a list literal in scalar context:

    my $x = (1, 2, 3);
    

    but the list literal does not result in a list, because the comma operator it contains sees scalar context, which then results in it returning the last item of the list literal, and throwing the remaining values away after evaluating them.

    In terms of a function, the function itself sees whatever context it is called from, which then is propagated to any line in that function that returns. So you can have a function in scalar, list, or void context, and if the last line of that sub happens to be a list literal, that list literal will see any of those contexts and will behave appropriately.

    So basically this is a terminology distinction, with list literal referring to a comma separated list of values in the actual source code*, and list referring to a sequence of values placed onto perl’s stack.

    You can write subroutines with return values that either behave like arrays or like list literals with regard to context.

    sub returns_like_array  {my @x = 1..5; return @x}
    
    sub returns_like_list   {my @x = 1..5; return @x[0 .. $#x]}
    

    *or something that results in a list of comma separated values, like a qw() or a fat comma => or a hash or array slice.

    You can also look at my answer here: How do I get the first item from a function that returns an array in Perl? which goes into a bit more detail about lists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is blowing my mind because it's probably an easy solution, but I can't
In my mind, a web app something that runs continuously; therefore, I'm confused by
Kindly don't mind my question as it is a little theoretical. Last week I
I need some mind reading here, since I am trying to do what I
In my mind, both modal dialogs and lightboxes serve the same purpose. It seems
Trying to get my mind around google protobuf. I found some implementation of protobuf
Update 3 : Never mind. I kinda got what I was looking for. The
This one boggles my mind. I've used this same script (different targets of course)
I don't mind so much about pirating etcetera, but I want to ensure that
I don't mind most of the way that VS2005 auto-indents (or auto-formats) my C++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.