Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Too much Hash??

by HamNRye (Monk)
on Jun 02, 2004 at 21:51 UTC ( #359771=note: print w/replies, xml ) Need Help??


in reply to Re: Too much Hash??
in thread Too much Hash??

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.

Replies are listed 'Best First'.
Re^3: Too much Hash??
by Errto (Vicar) on Jun 03, 2004 at 01:15 UTC

    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://359771]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-10-21 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (269 votes). Check out past polls.

    Notices?