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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Is there a reason it needs to be stored in the external file as perl code for hashes? Typically, you would store the data in a data format (CSV, XML, YAML, etc.), and read the data from the file in to build your Perl data structure (hash).

Alternately, if the data is more than a few entries, you might be better off leaving the data on disk, and accessing it on demand. My personal preference for that is SQLite (unless I have specific requirements that suggest something else). For your case, you might want to look at Tie::Hash or something alone that line. This type of module will store the contents of your hash in a database file. To your program, the hash looks and acts pretty much like a standard hash, but the data isn't stored in memory, it's stored on disk.

You could also use a module to implement data structure persistence. Something like Storable (or the numerous similar modules) might be useful for you. It will let you store a data structure (including a hash) on disk, and read it back into your program.

If you are insistent on storing the data as raw Perl code, you should review the documentation on require and do. These can be used to read in perl code from an external source.

Christopher Cashell

In reply to Re: using external file for hashes by topher
in thread using external file for hashes by r0adawg

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2022-08-17 08:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found