You values are being stored in the array exactly how you want them. The problem you are seeing comes simply in the output stage.

When you print out an array using code like:

print @out;

All the elements in the array are printed out with nothing between them. You can change this default behaviour by changing the value in $,. Perl prints the value of this variable inbetween the elements of an array. For example:

{ local $, = ':'; print @out; }

This prints the array elements separated with colons. Notice that I've localised the change to $, by putting it in a naked block. This is good practice for whenever you change the value of one of Perl's special variables.

Another technique you could use is to print the array in a double quoted dtring like this:

print "@out";

In this case, the default is to print the values separated by spaces. Once again this behaviour can be changed. In this case you need to chages the value of the $" variable, like this:

{ local $" = "\n"; print "@out"; }

In this case, the elements of @out will be separated by newline characters.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."


In reply to Re: I'm so confused by davorg
in thread I'm so confused by st4k

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.