Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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"; } } ...

In reply to Re: reading in a text file by csuhockey3
in thread reading in a text file by bzenker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found