Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Working with Hashes

by graff (Chancellor)
on Jun 12, 2016 at 13:45 UTC ( [id://1165420]=note: print w/replies, xml ) Need Help??


in reply to Working with Hashes

If you tell us a little more about the kind of application you are trying to build, rather than a particular technique you are thinking of using, you will probably get more helpful answers.

I gather you want a command-line script whose behavior will depend on the command-line arguments, and the different behaviors will depend on information that you want to store in distinct files that are separate from the command-line script. That's all fine and easy.

But you seem to want these extra files to be structured as perl code to define hashes. Is there some reason for not wanting to use some other common data file format, such as yaml or json or even xml? (There are good perl modules for these formats, making it easy to store and load any perl data structure you want via a data file.) So long as it's just a matter of selecting one set of data vs. another (including, say, one hash structure vs. another hash structure), reading different data files is the normal way (rather than selecting one vs. another block of perl code to be loaded and parsed after the main script has started running).

For any application where you might want to use one vs. another type of data structure (e.g. hash vs. array), and/or one vs. another set of subroutines, the normal way to do that is to create one or more object-oriented modules, such that there's always a consistent interface between the command-line script and each of the possible (objectified) things that it is supposed to know or do based on command-line args.

Normally, it's fine to load all the alternative modules (via use MyModuleX; use MyModuleY; ...), so that all possible behaviors are accessible on any given run, no matter what the command-line args may be. But if you have a compelling reason to want only the selected data and/or code to be loaded for a given run, just decide how your command-line args will relate to module loading, and then do this: require MyModuleX; (or whatever module), instead of use.

Replies are listed 'Best First'.
Re^2: Working with Hashes
by Anonymous Monk on Jun 14, 2016 at 12:33 UTC
    Hi,

    Thanks for the reply.

    Basically i want to write a utility which will cater to multiple scripts with its threshold values.

    So my utility will have add/update/fetch switches, add taking use input for the various threshold values and then pushing it in a separate file (say my_hashes.pl) in form of a hash (thats what I was planning to use till now).

    Fetch and update will be take argument and look for the same named hash in the file previously created (my_hashes.pl) , and display/use or update them.

      Above is the reply from my side, I replied without logging in :) ..

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found