[Moscow.pm] keys() и разыменование undef
TheAthlete
theathlet на yandex.ru
Вт Ноя 19 01:18:33 PST 2013
У меня аналогично.
В справке написано
Can't use an undefined value as %s reference
(F) A value used as either a hard reference or a symbolic reference must
be a defined value. This helps to delurk some insidious errors.
Хотя в справке по keys:
Starting with Perl 5.14, keys can take a scalar EXPR, which must contain a
reference to an unblessed hash or array. The argument will be dereferenced
automatically. This aspect of keys is considered highly experimental. The
exact behaviour may change in a future version of Perl.
Другими словами это экспериментальная фича.
Denis Ibaev <dionys на gmail.com> писал(а) в своём письме Tue, 19 Nov 2013
10:56:05 +0200:
> Привет.
>
>> perl -E 'use strictures; my $v; say(%$v);'
> Can't use an undefined value as a HASH reference at -e line 1.
>
>> perl -E 'use strictures; my $v; say(keys(%$v), "ok");'
> ok
>
> Почему разыменование переменной со значением undef в хеш не вызывает
> ошибки с случае keys() и values()?
>
>> perl -v
> This is perl 5, version 14, subversion 2 (v5.14.2) built for
> x86_64-linux-gnu-thread-multi
Подробная информация о списке рассылки Moscow-pm