Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: indefinite number of columns

by hippo (Monsignor)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044381]
and the radiator hisses contentedly...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2017-01-23 07:25 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (191 votes). Check out past polls.