Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
@stuff = "This","That","Other";

When I first saw this and other, similar code fragments in this thread, my first expectation was that the comma expression  "This","That","Other" would evaluate to the right-most list item, "Other". After all, that's the rule: Evaluate left side, throw away, return right side in left-associative fashion.

After a bit of thought, I realized that the rule is to evaluate the leftmost expression, toss the result, evaluate and return the result of the rightmost expression, left-associative. Of course, the leftmost expression has a side effect: it creates and initializes the  @stuff array. The following helped me elucidate the process:

>perl -wMstrict -MO=Deparse,-p -le "my @stuff = 'One', 'Two', 'Three'; print qq{(@stuff)}; ;; my @stoff = scalar('Eine', 'Zwei', 'Drei'); print qq{(@stoff)}; ;; my @sniff = scalar(my @snarf = '111', '222', '333'); print qq{sniff: (@sniff) snarf: (@snarf)}; ;; my @stiff = ('Uno', 'Dos', 'Tres'); print qq{(@stiff)}; " Useless use of a constant (Eine) in void context at -e line 1. Useless use of a constant (Zwei) in void context at -e line 1. Useless use of a constant (222) in void context at -e line 1. Useless use of a constant (Two) in void context at -e line 1. Useless use of a constant (Three) in void context at -e line 1. BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; ((my(@stuff) = 'One'), '???', '???'); print("(@stuff)"); (my(@stoff) = scalar(('???', '???', 'Drei'))); print("(@stoff)"); (my(@sniff) = scalar(((my(@snarf) = '111'), '???', '333'))); print("sniff: (@sniff) snarf: (@snarf)"); (my(@stiff) = ('Uno', 'Dos', 'Tres')); print("(@stiff)"); -e syntax OK >perl -wMstrict -le "my @stuff = 'One', 'Two', 'Three'; print qq{(@stuff)}; ;; my @stoff = scalar('Eine', 'Zwei', 'Drei'); print qq{(@stoff)}; ;; my @sniff = scalar(my @snarf = '111', '222', '333'); print qq{sniff: (@sniff) snarf: (@snarf)}; ;; my @stiff = ('Uno', 'Dos', 'Tres'); print qq{(@stiff)}; " Useless use of a constant (Eine) in void context at -e line 1. Useless use of a constant (Zwei) in void context at -e line 1. Useless use of a constant (222) in void context at -e line 1. Useless use of a constant (Two) in void context at -e line 1. Useless use of a constant (Three) in void context at -e line 1. (One) (Drei) sniff: (333) snarf: (111) (Uno Dos Tres)

In reply to Re: Newbie: query about array assignment by AnomalousMonk
in thread Newbie: query about array assignment by darren_uk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found