Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Setting arbitra...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 10930 of 12261
Post > Topic >>

Setting arbitrary-depth hash from file

by kelly.terry.jones@[EMAIL PROTECTED] (Kelly Jones) Apr 13, 2008 at 01:27 PM

I have a file with this in it:

a.b = 10
c.d.e = 11
f.g.h.i.j.k = 12

Based on that, I want to set:

$HASH{a}{b} = 10;
$HASH{c}{d}{e} = 11;
$HASH{f}{g}{h}{i}{j}{k} = 12;

This is easy using eval(), but is there a better way?

I realize that entries like "a.b = 10" and "a.b.c = 13" would
conflict, since setting $HASH{a}{b}{c} to 13 automatically sets
$HASH{a}{b} to a hashref. I've confirmed my file has no such conflicts.

This came up when I was looking at the output of snmpwalk. I realize
Perl has lots of modules to handle SNMP, but I was looking to do
something on my own.

-- 
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.
 




 7 Posts in Topic:
Setting arbitrary-depth hash from file
kelly.terry.jones@[EMAIL   2008-04-13 13:27:18 
Re: Setting arbitrary-depth hash from file
chas.owens@[EMAIL PROTECT  2008-04-13 16:36:50 
Re: [PBML] Setting arbitrary-depth hash from file
merlyn@[EMAIL PROTECTED]   2008-04-13 14:45:18 
Re: [PBML] Setting arbitrary-depth hash from file
rich.japh@[EMAIL PROTECTE  2008-04-13 21:31:00 
Re: [PBML] Setting arbitrary-depth hash from file
merlyn@[EMAIL PROTECTED]   2008-04-13 18:36:56 
Re: [PBML] Setting arbitrary-depth hash from file
merlyn@[EMAIL PROTECTED]   2008-04-14 04:19:08 
Re: [PBML] Setting arbitrary-depth hash from file
chas.owens@[EMAIL PROTECT  2008-04-13 22:38:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 17:42:11 CST 2008.