Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: arrange output in columns

by space_monk (Chaplain)
on Jun 18, 2013 at 12:22 UTC ( #1039556=note: print w/ replies, xml ) Need Help??


in reply to arrange output in columns

Update:Working version :-)

It's a slow day....
use strict; use warnings; use English; # let's talk like pirates.... my @arr; my $fc = 0; for my $file (@ARGV) { open my $fh, "<$file" or die "We're screwed with $file"; while (<$fh>) { chomp; # maybe s/\s+$// ? $arr[$INPUT_LINE_NUMBER][$fc] = $_; } close $fh; $fc++; # inc filecount } # print for (my $i =1; $i <= $#arr; $i++) { # fill in the blanks print join(',', map { $arr[$i][$_] // '' } 0..$fc-1)."\n"; }
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)


Comment on Re: arrange output in columns
Download Code
Re^2: arrange output in columns
by poj (Priest) on Jun 18, 2013 at 14:39 UTC
    "I might get the bugs out of this later.... "

    Here's the 3 missing characters you'll need to fix the script  = { }

    but even when fixed it doesn't give the required result for files with different record counts.

    Output Required a,2 a,2 b,f b,f c,4 c,4 s ,s w ,w
    poj
      Thanks for the input. I knocked this up in part of my lunchbreak while munching a burrito, and it was totally untested. :-)

      Update: I spotted the problems you mentioned before you posted and they've now been fixed.

      Anyway, as my footer says, it's polite to ensure that the reader still has to think through some of the issues, especially as this may be a homework assignment! :-)

      If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039556]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-09-19 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (143 votes), past polls