Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Too much Hash??

by robartes (Priest)
on Jun 02, 2004 at 21:15 UTC ( #359754=note: print w/ replies, xml ) Need Help??


in reply to Too much Hash??

It looks like $SubOption is being treated as a Hash reference.

No, but $Config{$Item} is. You're printing the values of the %Config hash, which are either hashrefs (in the case of sections with foo=bar lines) or scalars (in other cases). Nothing to be surprised at.

BTW, you'll be running into trouble when you have stanzas in your ini file which contain multiple lines without = in them (e.g. multiple email addresses in [Notify]). You might want to consider changing your data structure.

CU
Robartes-


Comment on Re: Too much Hash??
Download Code
Re^2: Too much Hash??
by HamNRye (Monk) on Jun 02, 2004 at 21:51 UTC

    Nothing to be surprised at.

    Well, it obviously suprised me. Thanks for telling me that this is normal behaviour, and I've done something stupid.

    Is that a syntax screw-up on my part then?? In my perl books, the closest syntax I can find is $hash{$key}{'string'} = $value, and that's pretty much what I've always used. I thought maybe the backslashes in the path were what was causing it. I've tried puting quotes around the vars (both single and double), escaping said quotes, and a few different syntaxes using the -> and => operators, etc.... I'm talking desperation stuff.

    Could someone at least point me to something that will give my desperation some focus??

    Here is an old write-up of mine that uses the same $MAIN::PageInfo{$section}{$pnum} = $_; style of putting things into a hash....

    Is this much like the last write-up where something is falling out of scope?

    Update

    From perldsc -

    # reading from file # flintstones: lead=fred pal=barney wife=wilma pet=dino while ( <> ) { next unless s/^(.*?):\s*//; $who = $1; for $field ( split ) { ($key, $value) = split /=/, $field; $HoH{$who}{$key} = $value; }

    That looks like roughly what I have, without the variables localized. I see I initialize $SubOption at the split, but even with that moved to the top of the sub it still fails.

      What do you mean by "fails?" It would be helpful if you showed us what your expected output is and where the actual output differs. To me it looks like your code is working just fine. To get a better sense of what's actually going on, you might try replacing

      foreach my $value (values %data){ print "$value\n"; }

      with something more like

      foreach my $value (values %data) { if (ref $value ne "HASH") { print "$value\n"; } else { print "$_\n" foreach values %$value; } }

      The point being, that when creating your main hash, some of your values are strings, others are hash references. That's the way your code is designed, so you'll need to change your handling routines to accomodate it.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-09-19 22:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (149 votes), past polls