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

  • SEARCH
  • Home
  • 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 6230363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:44:04+00:00 2026-05-24T09:44:04+00:00

There is a lie that a list in scalar context yields the last element

  • 0

There is a lie that a list in scalar context yields the last element of the list. This is a lie because (as the saying goes) you can’t have a list in scalar context. What looks like a list in scalar context is really the comma operator in scalar context and it has different behavior in scalar context.

However, there seems to be a loop hole in this logic: the null list (sometimes called the empty list). The characters () are defined to be the null list by perldoc perlglossary. The construct

my $s = ();

is valid code and returns undef to $s. This does not appear to be documented anywhere in perldoc (I haven’t checked the Camel), but lots of code counts on it, so I think it is here to stay.

Now that the preamble is done, here is the question: if we cannot have a list in scalar context, then what do we call the empty list in scalar context and what is the rational for not calling it a list (since there are no commas to be in scalar context)?

If you are enjoying this question, you may also like the discussion going on in P5P.

  • 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-24T09:44:05+00:00Added an answer on May 24, 2026 at 9:44 am

    List is a very generic word. You could possibly be referring to the list operator or to a list value.

    There is no comma in the code, so there is no list operator.

    There is no list context in the code, so there is no list value.

    Therefore, there is no list in

    my $s = ();
    

    Parentheses never create a list

    (Only indirectly when on the LHS of an assignment operator.)

    what do we call the empty list in scalar context

    Perl calls it a “stub” (as shown below), and that’s truly what it is. It’s a placeholder in the code where putting literally nothing would be disallowed.

    The stub is represented by “empty parentheses”, so that’s another name for it.

    I call it bad code. If you want to assign undef, assign undef.

    There is a lie that a list in scalar context yields the last element of the list.

    No, that’s true. List values cannot exist in scalar context, so that leaves the list operator.

    The list operator aka the comma operator returns the last element of the list in scalar context.


    Compare the following. No mention of list:

    >perl -MO=Concise -e"my $s = ();"
    6  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter ->2
    2     <;> nextstate(main 1 -e:1) v:{ ->3
    5     <2> sassign vKS/2 ->6
    3        <0> stub sP ->4
    4        <0> padsv[$s:1,2] sRM*/LVINTRO ->5
    -e syntax OK
    

    There is a mention of a list

    >perl -MO=Concise -e"my @a = ();"
    7  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter ->2
    2     <;> nextstate(main 1 -e:1) v:{ ->3
    6     <2> aassign[t2] vKS ->7
    -        <1> ex-list lK ->4
    3           <0> pushmark s ->4
    -           <0> stub lP ->-
    -        <1> ex-list lK ->6
    4           <0> pushmark s ->5
    5           <0> padav[@a:1,2] lRM*/LVINTRO ->6
    -e syntax OK
    

    …and it has nothing to do with the parens

    >perl -MO=Concise -e"my @a = 's';"
    8  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter ->2
    2     <;> nextstate(main 1 -e:1) v:{ ->3
    7     <2> aassign[t2] vKS ->8
    -        <1> ex-list lK ->5
    3           <0> pushmark s ->4
    4           <$> const[PV "s"] s ->5
    -        <1> ex-list lK ->7
    5           <0> pushmark s ->6
    6           <0> padav[@a:1,2] lRM*/LVINTRO ->7
    -e syntax OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the question is like this: there is a sorted list of n numbers. Given
Is there a good reference somewhere with all the C functions that can be
I have some discrete values and assumption, that these values lie on a Gaussian
I have a some additional xml files(containing standard eclipse extensions) that lie outside the
I'm assuming there is an easy way to do this, but I think that
There is a conversion process that is needed when migrating Visual Studio 2005 web
There is previous little on the google on this subject other than people asking
There are numerous Agile software development methods. Which ones have you used in practice
There is a field in my company's Contacts table. In that table, there is
Have I got that all the right way round? Anyway, I am parsing a

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.