[sf-perl] Use of uninitialized value in delete

Kevin Goess cpan at goess.org
Sat Oct 20 09:32:55 PDT 2012


It looks to me like that warning comes if the *key* you're trying to
delete is an uninitialized value, not the hash slot.

Though I notice that if you try to delete $x->{ $uninitialized_key }
you get "Use of uninitialized value $uninitialized_key in delete", to
get your error message I have to do this:

----------------------
use warnings;
use strict;

my $x;
my $uninitialized_key;
my $undef_key_generator = sub { return undef };

# doesn't warn
delete $x->{a};

# Use of uninitialized value $uninitialized_key in delete at test.pl line 10.
delete $x->{ $uninitialized_key };

# Use of uninitialized value in delete at test.pl line 11.
delete $x->{ $undef_key_generator->() };

----------------------

On Thu, Oct 18, 2012 at 2:07 PM, Bill Moseley <moseley at hank.org> wrote:
>
>
> I'm seeing "Use of uninitialized value in delete" for this line:
> delete $c->stash->{foo};
>
> Perl 5.14.2.
> Obviously, that's in Catalyst, and it's running under mod_perl.
>
> I didn't think that delete issued a warning, and I can't seem to make it happen:
>
> $ perl -Mwarnings -Mstrict -Wle 'use warnings; use strict; my $x = {}; delete $x->{a}'
> Am I missing something obvious here?
>
>
> --
> Bill Moseley
> moseley at hank.org
>
>
>
> --
> Bill Moseley
> moseley at hank.org
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>


More information about the SanFrancisco-pm mailing list