The first line sets the variable $a to contain the bareword 'a', which would be a big problem if you were using strict, but definitely not the only problem. ;) So $a will contain 'a'. The second line is similar.

The third and fourth lines are probably bugs, though they do compile. @x = qw(a,b,c); is really only assigning ONE value to the array @x. The value is the literal string, "a,b,c" (a single string). In other words, the script is probably using the qw// operator in a way that is visually misleading.

The fifth line takes @x in scalar context and prints the result. An array in scalar context divulges its number of elements. Since you only assigned one literal string to @x (not three distinct values), you see the number '1' get printed; only one element.

The sixth line checks to see if $a is less than $b. It should output the content of @x, which will appear as 'a,b,c' (giving the illusion of a list, though it's actually just a literal string in this case).

The eighth line is assigning the string held in the first (and only element) of @x to $a, and then it gets printed on the last line of the script.

It really looks to me like someone just wanted to be cute and send you on a goose chase trying to figure out why a list prints yet seems to be only one element. The fact is that there's only one element held in each array, and the singular elements are strings that have the appearance of lists.


Dave


In reply to Re: Perl interpretor for conditional operator "?" by davido
in thread Perl interpretor for conditional operator "?" by yramesh.1981

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.