Is the space actually in the array rows, or is it just being added when you print the array ?

I ran into this recently, and found out that the spaces weren't actually in the array.

If you're printing the array with something like:

print "@TheArray";

and you don't have an extra space in front of the first line, but you do have an extra space in front of all other lines, the spaces probably aren't in the array.

Perl by default seperates the array with spaces in an interpolative context (meaning if you have the array inside double quotes). That's why the first row doesn't have a space in front of it - the first row doesn't need to be seperated from another row in front of it, because it's the first row.

If you print with something like this, the extra spaces won't show up:

print @TheArray;

Without the "", Perl doesn't interpolate the array, meaning it doesn't seperate the rows with spaces. The following script line also works, but is more verbose. I tend to write scripts that are more verbose, because I'm not a Perl Master yet :)

foreach $ArrayRow( @TestArray ) { print $ArrayRow; }

Here's a demo script:
#!C:\Perl\bin #use warnings; #use strict; my $ArrayRow = ""; splice( my @TestArray ); $ArrayRow = "20130516,530,730\n"; push( @TestArray, $ArrayRow ); $ArrayRow = "20130516,731,1100\n"; push( @TestArray, $ArrayRow ); $ArrayRow = "20130516,1101,1200\n"; push( @TestArray, $ArrayRow ); print "@TestArray"; print "\n\n"; print @TestArray; print "\n\n"; foreach $ArrayRow( @TestArray ) { print $ArrayRow; } print "\n\n";
Dyslexics Untie !!!

In reply to Re: Manipulation of output of multiple parse line. by JockoHelios
in thread Manipulation of output of multiple parse line. by flynnbg

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.