in reply to zlib error

The short answer to your issue is that 'Compress::Zlib::' is a string and not a hash reference, so perl fails when it tries to dereference the string (%$package). At first I thought you were saying that the posted code was from Compress::Zlib, but I find no such code, so I'll assume that is code in a local module. What are you trying to do by defining $package? Are you the original author of Gzip.pm? This looks a lot like using symbolic references to muck about in the package symbol table, which is not allowed under strict 'refs'.

Replies are listed 'Best First'.
Re^2: zlib error
by almut (Canon) on Apr 19, 2010 at 16:43 UTC
    so perl fails when it tries to dereference the string

    Interestingly, the code

    my $package = "Compress::Zlib::"; print "$package defined\n" if defined %$package;

    works fine with 5.8.8 (with strictures enabled), while 5.10.1 complains as shown in the OP...

    Update: and with 5.12.0 you get

    defined(%hash) is deprecated at ./835534.pl line 10. (Maybe you should just omit the defined()?)

    ...which also does work fine (with strictures) when you do so, i.e. when you write ... if %$package;  nonsense (I had forgotten to comment out the no strict 'refs', which I had added in the meantime...) — in other words, for both 5.10 and 5.12 (but not 5.8) you do need the no strict 'refs', even without the deprecated defined %...

      which also does work fine (with strictures)

      Not for me.

      $ perl -v This is perl 5, version 12, subversion 0 (v5.12.0) built for i686-linu +x [snip] $ perl -Mstrict -wle'my $pkg="Foo::"; print(defined(%$pkg)?1:0)' defined(%hash) is deprecated at -e line 1. (Maybe you should just omit the defined()?) Can't use string ("Foo::") as a HASH ref while "strict refs" in use at + -e line 1.

      Update: Oops, seems you noticed your mistake while I was posting.