Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: arrange output in columns

by rjt (Deacon)
on Jun 17, 2013 at 18:46 UTC ( #1039444=note: print w/ replies, xml ) Need Help??


in reply to arrange output in columns

I could give you hints and try to string you along, but for a self-professed newbie to Perl, sometimes a good example is more instructive than coming up with a sub-optimal solution of your own:

use warnings; use strict; my @fh; # Store filehandles open $fh[@fh], '<', $_ or die "Can't open `$_': $!" for <1039418/*.tx +t>; while (1) { no warnings qw/uninitialized io/; my $line; $line .= <$_> // "\n" for @fh; last if $line =~ /^\n*$/; # All files finished or blank $line =~ s/\n(?!\z)/,/g; # Delimit with commas, except for last +\n print $line; }

The challenge to you, james4545, is to take this and understand it. Break it apart. Figure out why each statement does what it does. Put it back together in a different way. Ask specific questions. Thoroughly read the documentation for each of the functions, plus perlop and perlre. Watch an episode of Futurama and then code it (this example, not Futurama) yourself from scratch without looking. Meditate on the beauty of =~ . Have a @π[1..3]. And then so shall you follow the path of a Perlmonk.

Or, by all means, copy/paste this code and move on. As much as we like to see others walk the monastic path, we monks tend to be a self-satisfied bunch.


Comment on Re: arrange output in columns
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (15)
As of 2014-10-20 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (89 votes), past polls