Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Another flatfile thingy

by eak (Monk)
on Aug 04, 2000 at 10:02 UTC ( #26139=note: print w/replies, xml ) Need Help??

in reply to Another flatfile thingy

I am parsing the flatfile into an AoH. This makes it very easy to get at a row, than a column. Please note the cool map that creates the reference to a hash.
ID    NAME1    NAME2    AGE
1    donald    duck    50
2    mickey    mouse    48
3    peter    pan    62
4    madre    theresa    108
5    banana    split    2 
#!/usr/bin/perl -w use strict; use IO::File; my $fh = new IO::File; $fh->open("< foo.txt") or die "can't open foo.txt $!"; my @file = map{ [split /\s+/]; } <$fh>; my $keys = shift @file; print "The keys are:\n"; print join("\t",@$keys )."\n"; my @aoh = map{ my %hash; @hash{@$keys} = @$_; \%hash} @file; print "Row 3 is \n"; print join("\t", @{$aoh[2]}{@$keys} )."\n"; print "Column 'NAME2' is:\n"; foreach my $row (@aoh) { print $row->{NAME2}."\n"; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2022-01-22 22:14 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (63 votes). Check out past polls.