in reply to Re: Odd hash problem.
in thread Odd hash problem.

Hmm.. a little more info..

The reason behind my %data was to localise it to the module. It works without the my, but if I later open another file of data that had the same 'primary keys' it'd overwrite the previous ones. Using my made it local to the particular reference. (Maybe blessing the reference into the package would be a good idea?)

As for the warnings, its a CGI thing, I'm using CGI qw(fatalsToBrowser);, which doesn't chuck out anything nasty at the moment. I'll check it with the -w option when I get away from the ASP stuff I'm writing in the office. By the way, should have mentioned before, this is Perl on Win32.. don't think it'll make a big difference, but it might.

Replies are listed 'Best First'.
Re: Re: Re: Odd hash problem.
by Fastolfe (Vicar) on Jan 02, 2001 at 19:56 UTC
    If you need to preserve the value of an existing variable only for the duration of a small block, perhaps you want local instead of my. Using 'my' on a variable already declared in the current scope will also generate a warning. Simply localizing its value with local is what you want to do here. This will also set its value to empty within the block you're using it, so a local %hash; is sufficient to get an empty %hash until you leave that block of code, at which point the original value is restored.

    And the CGI::Carp bit is only useful if your application generates its own warnings/errors (including fatal error messages). Add the -w option to Perl (or with 5.6, 'use warnings;') so that Perl will take a look at your code and warn you when things don't look quite right, as it would have in this case.