Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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?


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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://359771]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2018-06-20 17:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.