[Moscow.pm] reverse изменяет аргумент

Denis Evdokimov evdokimov.denis на gmail.com
Пн Окт 1 09:58:58 PDT 2012


Мне кажется, что в этом куске документации ничего не сказано про это
поведение.

2012/10/1 iSage <isage на aumi.ru>

> Знаем. Только если аргументом хэш. И об этом сказано в документации.
>
> This operator is also handy for inverting a hash, although there are some
> caveats. If a value is duplicated in the original hash, only one of those
> can be represented as a key in the inverted hash. *Also, this has to
> unwind one hash and build a whole new one*, which may take some time on a
> large hash, such as from a DBM file.
>
> On Mon, 1 Oct 2012 19:20:52 +0400, Denis Evdokimov <
> evdokimov.denis на gmail.com> wrote:
>
> А знаете ли вы, что reverse изменяет свой агрумент?
> В этом легко убедиться с помощью JSON или Devel::Peek :
>
> perl -MJSON -e'my %a=(int => 222); print to_json \%a; my %b=reverse %a;
> print to_json \%a;'
> {"int":222}{"int":"222"}
>
> perl -MDevel::Peek -e'my %a=(int => 222); Dump $a{int}; my %b=reverse %a;
> Dump $a{int};'
> SV = IV(0x1036d40) at 0x1036d48
>   REFCNT = 1
>   FLAGS = (IOK,pIOK)
>   IV = 222
> SV = PVIV(0x1051220) at 0x1036d48
>   REFCNT = 1
>   FLAGS = (IOK,POK,pIOK,pPOK)
>   IV = 222
>   PV = 0x1056220 "222"\0
>   CUR = 3
>   LEN = 8
>
>
>
> --
> Moscow.pm mailing list
> moscow-pm на pm.org | http://moscow.pm.org
>
>
----------- следущая часть -----------
Вложение в формате HTML было извлечено…
URL: <http://mail.pm.org/pipermail/moscow-pm/attachments/20121001/cb5de658/attachment.html>


Подробная информация о списке рассылки Moscow-pm