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 3997064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:21:21+00:00 2026-05-20T07:21:21+00:00

from Programming Perl pg 90, he says: @ary = (1, 3, sort 4, 2);

  • 0

from Programming Perl pg 90, he says:

   @ary = (1, 3, sort 4, 2);
    print @ary;

the commas on the right of the sort are evaluated before the sort but the commas on the left are evaluated after. … list operators tend to gobble .. and then act like a simple term”

  1. Does the assignment result in sort being processed or does that happen when @ary is expanded by print?
  2. What does he mean by all that “comma” stuff?? My understanding is that in the assignment statement, comma has a lower priority than a list operator therefore sort runs first and gobbles up it’s arguments (4 and 2).. How the heck is comma being evaluated at all?? So that statemnent then becomes (1, 3, 2, 4) a list which is assigned.. comma is just acting as a list separator and not an operator!! In fact on pg:108 he says: do not confuse the scalar context use of comma with list context use..
  3. What is a leftward and rightward list operator? print @ary is a rightward list operator?? So it has very low priority?

    print($foo, exit);

here, how is precedence evaluated? print is a list operator that looks like a function so it should run first! it has two arguments $foo and exit.. so why is exit not treated as a string??? After all priority-wise print(the list operator) has higher priority??

print $foo, exit;

here, you have print and , operators but the list operator has higher precedence.. so.. exit should be treated as a string – why not??

   print ($foo & 255) + 1, "\n";

here since it’s a list operator it prints $foo & 255 Shouldn’t something similar happen with the above mentioned exit stuff..

  • 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-20T07:21:22+00:00Added an answer on May 20, 2026 at 7:21 am

    When in doubt about how Perl is parsing a construct, you can run the code through the B::Deparse module, which will generate Perl source code from the compiled internal representation. For your first example:

    $ perl -MO=Deparse,-p -e '@ary = (1, 3, sort 4, 2); print @ary;'
    (@ary = (1, 3, sort(4, 2)));
    print(@ary);
    -e syntax OK
    

    So as you can see, sort takes the two arguments to its right.

    As far as execution order goes, you can find that out with the B::Concise module (I’ve added the comments):

    $ perl -MO=Concise,-exec -e '@ary = (1, 3, sort 4, 2); print @ary;'
    1  <0> enter 
    2  <;> nextstate(main 1 -e:1) v:{
    3  <0> pushmark s       # start of list
    4  <$> const[IV 1] s    # 1 is added to list
    5  <$> const[IV 3] s    # 3 is added to list
    6  <0> pushmark s       # start of sort's argument list
    7  <$> const[IV 4] s    # 4 is added to sort's argument list
    8  <$> const[IV 2] s    # 2 is added to sort's argument list
    9  <@> sort lK          # sort is run, and returns its list into the outer list
    a  <0> pushmark s
    b  <#> gv[*ary] s
    c  <1> rv2av[t2] lKRM*/1
    d  <2> aassign[t3] vKS/COMMON  # the list is assigned to the array
    e  <;> nextstate(main 1 -e:1) v:{
    f  <0> pushmark s         # start of print's argument list
    g  <#> gv[*ary] s         # the array is loaded into print's argument list
    h  <1> rv2av[t5] lK/1
    i  <@> print vK           # print outputs it's argument list
    j  <@> leave[1 ref] vKP/REFC
    -e syntax OK
    

    For your second example:

    $ perl -MO=Deparse,-p -e 'print $foo, exit;'
    print($foo, exit);
    -e syntax OK
    
    $ perl -MO=Concise,-exec -e 'print $foo, exit;'
    1  <0> enter 
    2  <;> nextstate(main 1 -e:1) v:{
    3  <0> pushmark s
    4  <#> gvsv[*foo] s   # add $foo to the argument list
    5  <0> exit s         # call `exit` and add its return value to the list
    6  <@> print vK       # print the list, but we never get here
    7  <@> leave[1 ref] vKP/REFC
    -e syntax OK
    

    So as you can see, the exit builtin is run while trying to assemble the argument list for print. Since exit causes the program to quit, the print command never gets to run.

    And the last one:

    $ perl -MO=Deparse,-p -e 'print ($foo & 255) + 1, "\n";'
    ((print(($foo & 255)) + 1), '???');  # '???' means this was optimized away
    -e syntax OK
    
    $ perl -MO=Concise,-exec -e 'print ($foo & 255) + 1, "\n";'
    1  <0> enter 
    2  <;> nextstate(main 1 -e:1) v:{
    3  <0> pushmark v
    4  <0> pushmark s
    5  <#> gvsv[*foo] s
    6  <$> const[IV 255] s
    7  <2> bit_and[t2] sK
    8  <@> print sK
    9  <$> const[IV 1] s
    a  <2> add[t3] vK/2
    b  <@> list vK
    c  <@> leave[1 ref] vKP/REFC
    -e syntax OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand the last line of this function from Programming Perl 3e .
I am still learning socket programming (using Perl) but I have both options (
I am fairly new to Perl programming, but I have a fair amount of
Newish to Oracle programming (from Sybase and MS SQL Server). What is the Oracle
I'm learning iPhone programming from Erica Sadun's The iPhone Developer's Cookbook. When I run
From Wikipedia : Generic programming is a style of computer programming in which algorithms
Below are lines from the c++ programming language template<class T > T sqrt(T );
I'm playing with the distributed programming tutorial from the 5.4 documentation, and have run
From day 1 of my programming career, I started with object-oriented programming. However, I'm
From using a number of programming languages and libraries I have noticed various terms

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.