Well I was coding for too long at one time again and
I made a silly mistake that had me scratching my head.
I had:
my @array = ('red','green','blue');
print @array . "\n";
But it was printing '3' instead of what I thought it should
which is 'redgreenblue'
Since it was inside a loop I thought it might be a scoping
issue. I poked around a bit and finally I took a break.
Then it occured to me, "Comma not period!".
So I changed to the code to read:
my @array = ('red','green','blue');
print @array , "\n";
And everything is fine, well almost.
Its bugging my why it was returning the number of elements
instead of nothing or an error. It is my assumption that
the '.' forces the variable to be printed in
a scalar context instead of as a list.
I also assume that the ',' is simply adding a element to
the list since ',' is a list seperator character. I found
something in the Camel book in the Efficiency section, but
it only explained that the ',' is faster in some cases when
doing a concatenation. I never really gave this much thought
until I used the wrong concatenation character.
What book can I refer to for a detailed explaination?
Are my assumptions correct?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.