Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Clean out da hash...

by GaijinPunch (Pilgrim)
on Feb 12, 2004 at 08:28 UTC ( #328504=note: print w/replies, xml ) Need Help??


in reply to Re: Clean out da hash...
in thread Clean out da hash...

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.

Replies are listed 'Best First'.
Re: Re: Re: Clean out da hash...
by ysth (Canon) on Feb 12, 2004 at 08:53 UTC
    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..
        After you have called clean_hash, why don't you check its contents with
        use Data::Dumper; ... clean_hash(); print STDERR Dumper(\%hash); ...

        +++++++++++++++++
        #!/usr/bin/perl
        use warnings;use strict;use brain;

        If you start stripping down the code to be short enough to show (but still demonstrably broken), you'll probably stumble across the answer.
Re: Clean out da hash...
by Abigail-II (Bishop) on Feb 12, 2004 at 09:57 UTC
    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

Re: Re: Re: Clean out da hash...
by boo_radley (Parson) on Feb 12, 2004 at 15:12 UTC

    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
Node Status?
node history
Node Type: note [id://328504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2020-12-04 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (58 votes). Check out past polls.

    Notices?