Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Clean out da hash...

by ysth (Canon)
on Feb 12, 2004 at 08:16 UTC ( [id://328501]=note: print w/replies, xml ) Need Help??


in reply to Clean out da hash...

I have a feeling that %hash is a my() variable and your clean_hash routine isn't in its scope. Are you using strict?

The easier way to clear a hash is to say: %hash = ();

Replies are listed 'Best First'.
Re: Re: Clean out da hash...
by GaijinPunch (Pilgrim) on Feb 12, 2004 at 08:28 UTC
    I thought
    %hash = ();
    would work, but it's not. And yes, I am using strict. The code is a bit long, but an abridged version is:
    use strict; use warnings; my %hash; my @sets = qw(set_a set_b); foreach my $set ( @sets ) { &find_start($set); #defines start and end points to grab data &fill_hash(); # fill 'er up &print_hash(); #print out &clean_hash(); #clean it out }
    The &find_start() looks throught the 6000 lines of text, and decides which line to start grabbing data, and which line to stopt at, based on the value of $set. I thought maybe I was grabbing the wrong stuff, but everything "adds up". Pun intended.
      Are you absolutely certain those subs are using the same %hash as is declared there? (Try sticking some print \%hash; statements in the foreach loop and at the beginning of the *_hash subs.) Are the subs in the same source? Do you have another my %hash statement? You aren't tweaking the readonly flag on %hash, are you?
        I'm very sure there's no other hash references in there. I double checked that. I don't know anything about read only flags, so I suspect it's not that.

        I'm going over everything again, and haev even sucked a colleague in, but I've stumped him as well.

        Grrrrr..
      That doesn't show the code of &clean_hash, and that's where this is about.

      Could you provide us with a short, self contained program that shows that %hash = (); doesn't clear the hash in all cases?

      Abigail

      Your code snippet is too short. I appreciate your desire to be brief, but we're missing some criticial bits, chief of which is the contents of the clean_hash subroutine.

      If I had to rely on intuition, though, I'd bet you were redeclaring your hash in clean_hash. This isn't a good or bad thing, entirely, because you should delete this call altogether, and replace it with the %hash=() that people have advised it'll get rid of your scoping error altogether. Wrapping such a trivial line of code in a sub makes baby Jesus cry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-18 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found