Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

RE: Creating the right type of array...

by Boogman (Scribe)
on Aug 30, 2000 at 00:42 UTC ( [id://30210]=note: print w/replies, xml ) Need Help??


in reply to Creating the right type of array...

I would use a hash which held references to arrays of arrays. You could use the first column as the key, and hold a reference to an array where each element is a reference to an array holding the data of each line that had that key. Sounds complicated, but isn't too bad once you get the hang of it.

heres some sample code:
#!/usr/bin/perl use warnings; use strict; open FILE, "input" || die "Couldn't open file"; my %hash; while ( <FILE> ) { chomp; my ( $key, @rest ) = split /,/; foreach ( 0 .. 4 ) { $rest[$_] = "" unless ( defined( $rest[$_] ) ); } push @{ $hash{$key} }, \@rest; } # To print out every 1st row of all the ones beginning with QTY print "$_->[0]\n" foreach ( @{ $hash{QTY} } ); # total number of entries for the category print scalar( @{ $hash{QTY} } ); # print a specific row of data print "@{ $hash{QTY}[2] }\n";
Update: Hehehe... looks like i was beaten to it... oh well... the more the merrier, right?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found