Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: reading in a text file

by csuhockey3 (Curate)
on Jan 03, 2005 at 05:30 UTC ( #418874=note: print w/replies, xml ) Need Help??


in reply to reading in a text file

I had a similar task the other day (although it was dbm, it could just as well have been a text file). I had a bunch of information in these files that I needed to strip out and place in a hash -- namely county codes and their corresponding email aliases. Sounds like you would just need to modify this by using opendir / readdir etc as pointed out by chanio and prasadbabu to avoid hard coding the file name(s) and allow traversing the directory.

Post some of your code and we can help you more, til then here is a little snippet that can give you something to start with:
#!/usr/bin/perl -wT dbmopen(%ISO_Country, "ISO_Country", 0777) or die "Cannot create ISO_Country: $1\n\n"; dbmopen(%ISO_Email, "ISO_Email", 0777) or die "Cannot create ISO_Email: $1\n\n"; open FNAME, $ARGV[0] or die "Cannot locate file $ARGV[0]: $1"; while ($line = <FNAME>){ chop($line); @data = split /\t/, $line; $ISO_Country{$data[0]} = $data[1]; $ISO_Email{$data[0]} = $data[2]; } &displayData; dbmclose(%ISO_Country); dbmclose(%ISO_Email); sub displayData{ while (($key, $value) = each %ISO_Country){ print "ISO($key), Country($value)\n"; } while (($key, $value) = each %ISO_Email){ print "ISO($key), Email($value)\n"; } } ...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2021-01-23 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?