Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
P is for Practical
 
PerlMonks  

Re: indefinite number of columns

by hippo (Chaplain)
on Jul 15, 2013 at 13:53 UTC ( #1044381=note: print w/ replies, xml ) Need Help??


in reply to indefinite number of columns

if I want column 1 entries to go in one array , second column entry to another and so on . How can i define my array
use strict; use warnings; use Data::Dumper; my $ncols = 5; # or obtained from user my @bigfatarray = (); push @bigfatarray, [] for [1 .. $ncols]; while (<DATA>) { my @cols = split (/,/, $_); for my $i (0 .. $ncols - 1) { push @{$bigfatarray[$i]}, $cols[$i]; } } print Dumper (\@bigfatarray); exit; __DATA__ 1,2,3,4,5 a,b,c,d,e

Obviously, you'll need to do more than just split your inputs but this should serve as an illustration.


Comment on Re: indefinite number of columns
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-04-24 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls