Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: indefinite number of columns

by hippo (Parson)
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 cooling their heels in the Monastery: (8)
As of 2016-02-09 18:38 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (322 votes), past polls