Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: arrange output in columns

by space_monk (Chaplain)
on Jun 18, 2013 at 12:22 UTC ( [id://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! :-)

Replies are listed 'Best First'.
Re^2: arrange output in columns
by poj (Abbot) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1039556]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2025-11-11 13:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.