Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: indefinite number of columns

by hippo (Vicar)
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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2015-08-28 17:47 GMT
Find Nodes?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...

    Results (338 votes), past polls