azredwing has asked for the wisdom of the Perl Monks concerning the following question:
The thing is, some commands will run around 35 to 40 times, and to keep them all in one column is not exactly a great use of space considering these reports are printed and kept hard-copy. So, what I need is a way to create multiple columns (up to 4) based on how many entries there are in the array in which I keep those numbers. I wrote a fast solution to do this with duplicate commands/arguments as the entries, but it's not the most elegant (I begin teaching myself Perl about a month ago):Command 01a3 executed 6 times: 0213 0214 0215 0216 0217 0218
While I can probably use this code to implement multiple columns, I would probably screw something up when it came time to maintain it. It took forever to tweak that code as it was to make sure I didn't either accidentally reprint a line or skip a line. Any ideas? I'd be much obliged.###this code only prints up to 3 columns, not 4 print OUT "\nThe following ", scalar @dupes, " tokens were duplicated: +\n"; if(@dupes<=10) { foreach (@dupes) { print OUT "\t$_\n"; } } elsif(@dupes<=20) #print two columns of dupes { for($i=0; $i<=10; $i++) { if(defined ($dupes[10+$i])) { $_=$dupes[$i]."\t".$dupes[10+$i]; } else { $_=$dupes[$i]; } print OUT "$_\n"; } } else #print three columns { no warnings; for($i=0; $i<=(@dupes/3); $i++) { if(defined $dupes[$i+(2/3)*@dupes]) { $_=$dupes[$i]."\t\t".$dupes[(1/3)*@dupes+$i+1]."\t\t".$dup +es[(2/3)*@dupes+$i+2]; } elsif(defined $dupes[$i+(1/3)*@dupes]) { $_=$dupes[$i]."\t\t".$dupes[(1/3)*@dupes+$i+1]; } else { $_=$dupes[$i]; } print OUT "\t$_\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Long array -> multiple columns?
by ikegami (Patriarch) on Jan 30, 2008 at 06:38 UTC | |
by azredwing (Sexton) on Jan 30, 2008 at 06:46 UTC | |
by ikegami (Patriarch) on Jan 30, 2008 at 06:52 UTC | |
|
Re: Long array -> multiple columns?
by ikegami (Patriarch) on Jan 30, 2008 at 07:00 UTC | |
by azredwing (Sexton) on Jan 30, 2008 at 07:16 UTC | |
|
Re: Long array -> multiple columns?
by moritz (Cardinal) on Jan 30, 2008 at 06:48 UTC | |
by ikegami (Patriarch) on Jan 30, 2008 at 06:53 UTC | |
by azredwing (Sexton) on Jan 30, 2008 at 06:56 UTC | |
|
Re: Long array -> multiple columns?
by halley (Prior) on Jan 30, 2008 at 15:21 UTC | |
by ikegami (Patriarch) on Jan 30, 2008 at 21:40 UTC |