Re: Restoring a Data Structure from a File
by Fletch (Bishop) on Nov 02, 2007 at 13:59 UTC
|
You could switch to a serialization format that while readable and easily manipulated by hyoomons doesn't require direct parsing by the Perl interpreter (say YAML or XML).
| [reply] |
|
|
fletch-
GREAT idea! Many thanks. I knew someone here would shine a light down one or two of the dark alleys that I never bother to turn the lights on for.
BTW: What is a hyoomon (and how do you pronounce it)? All my searches turn up folks using it, but no one with a definition.
Never heard that one before...
-Craig
UPDATE:
XML::Simple doesn't work because I can't use @ in my hash key names.
As stated in the docs: hash keys from the data structure will be encoded as either XML element names or attribute names. Therefore, you should use hash key names which conform to the relatively strict XML naming rules..."
YAML::Syck Seems to work fine.
PS - Thanks for the help with huh-yoo-man too. I love it!
| [reply] |
Re: Restoring a Data Structure from a File
by KurtSchwind (Chaplain) on Nov 02, 2007 at 14:35 UTC
|
Considering your specific example, I'd probably steer clear of XML. It's way over-kill for what you are looking for. There is no reason to not do something as simple as a text file where you put one address per line.
Joe@Host1.fqdn
Schmoe@Host2.fqdn
and simply read the file in if it's there. It's super easy to edit in any given editor. And it's trivial to read in as well. You can loop through and build the array in what... 3 lines? And dumping it out is just as easy.
Don't over-engineer this. And yes, you are wise to not just blindly eval a document into the program. It sounds like a good app.
--
I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.
| [reply] [d/l] [select] |
|
|
Kurt-
You did good in pointing out the KISS solution here, as I failed to properly state the scope of the problem in my original request.
Actually, this is how I started doing things, but ended up with data-feature-creep, as I kept adding bits of information about each usr@host. Things now look something like this:
'me@hawaii' => {
'SSHinfo' => {
'Login' => 'myusr@warm.hawaii.com',
'socks_proxy' => 'mysocksproxy.com',
'socks_port' => 1234,
'socks_protocol' => 4,
'identity_files' => [ "$HOME/.sshspecial/toolauth" ],
'user_known_hosts' => "$HOME/.sshspecial/knownhosts",
},
...
},
...
Having all this data tied to each entry, it'll be better for me to save the structure.
-Craig | [reply] [d/l] |
|
|
| [reply] |
Re: Restoring a Data Structure from a File
by NetWallah (Canon) on Nov 02, 2007 at 16:16 UTC
|
Having been down this road before, I'd advise you to save, and verify data VERSION information.
In other words, make sure the VERSION of the data, and the program structure the data imports into are compatible.
This is critical to feature-creep applications. Also have suitable defaults for each feature you add, so older stored data can remain compatible.
"As you get older three things happen. The first is your memory goes, and I can't remember the other two... "
- Sir Norman Wisdom
| [reply] |
|
|
NetWallah This is an excellent suggestion, which I will be adding to my code as soon as possible. I've already been tripped up with data version problems in some other code I've written, but never thought to do anything about it. Many thanks for the suggestion!
-Craig
| [reply] |
Re: Restoring a Data Structure from a File
by dragonchild (Archbishop) on Nov 02, 2007 at 16:25 UTC
|
Unless the data needs to be human-readable, why not just use DBM::Deep? That allows you to treat your serialization directly as a Perl data structure. And, for bulk-additions, just whip together a little script that adds the stuff to the Perl data structure that is your file.
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |
Re: Restoring a Data Structure from a File
by holli (Abbot) on Nov 02, 2007 at 22:00 UTC
|
Since this sounds to a ajaxian thingy i recommend JSON. It plays nice with Javascript, is easy to note and familiar for you (just replace => by : and you're mostly done). As for YAML, it is error prone for manual editing. eg, a whitespace/newline (or none) at the wrong place may lead to fatal parsing errors.
| [reply] [d/l] |
|
|
| [reply] |
|
|
| [reply] |
|
|