in reply to Manipulation of output of multiple parse line.
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Manipulation of output of multiple parse line.
by flynnbg (Initiate) on Jun 13, 2013 at 06:07 UTC |