Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to print to file a tab delimited array I've just sorted. Linebreaks are elements in the array that signify new lines as new entries. The problem is that the Join function adds a tab to every element, including \n, which presents itself at the beginning of every line. I've written the following test snippet in an attempt to cut the tab following a \n out, but for the life of me it will not work. I humbly ask for your wisdom, good monks.
use warnings; use strict; open (outputFile, ">", "TestNew.txt"); my @infoArray = (1, 2, 3, 4, 5, '\n', 6, 7, 8, 9, 10, '\n'); my $x = 0; my $test = "\n"; my @finalArray = join ("\t", @infoArray); foreach (@finalArray) { if ($_ eq $test) { splice (@finalArray, $x + 1, 1); } else { $x = $x + 1; } } print outputFile @finalArray;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splicing the next element in an array
by zwon (Abbot) on Apr 08, 2014 at 16:04 UTC | |
by Anonymous Monk on Apr 08, 2014 at 17:07 UTC | |
|
Re: Splicing the next element in an array
by Laurent_R (Canon) on Apr 08, 2014 at 16:46 UTC | |
|
Re: Splicing the next element in an array
by AnomalousMonk (Archbishop) on Apr 08, 2014 at 17:44 UTC | |
|
Re: Splicing the next element in an array
by kcott (Archbishop) on Apr 08, 2014 at 21:15 UTC |