Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (10)
    As of 2015-07-03 08:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (50 votes), past polls