[Moscow.pm] while без условий

Alex Shatlovsky shatlovsky на gmail.com
Вт Фев 26 03:21:42 PST 2008


On 2/26/08, Alex Kapranoff <alex на kapranoff.ru> wrote:
> Denis Evdokimov wrote:
>  > почему конструкция вида:
>  > while() {}
>  > Приводит к бесконечному циклу?
>
>
> Капитан Депарс спешит на помощь:
>  % perl -MO=Deparse -e 'while() {}'

По поводу "-MO=Deparse".

Насколько я понял из манов, тут вызывается модуль B::Deparse (Perl
compiler backend to produce perl code) как бэкенд к O (Generic
interface to Perl Compiler backends):

В perl-коде в общем случае это выглядит как
use O ("Backend", OPTIONS);

Цитата из perlcompile:

=====
Perl has always had a compiler: your source is compiled into an
internal form (a parse tree) which is then optimized before being run.
Since version 5.005, Perl has shipped with a module capable of
inspecting the optimized parse tree (B), and this has been used to
write many useful utilities, including a module that lets you turn
your Perl into C source code that can be compiled into a native
executable.

The B module provides access to the parse tree, and other modules
("back ends") do things with the tree. Some write it out as
semi-human-readable text. Another traverses the parse tree to build a
cross-reference of which subroutines, formats, and variables are used
where. Another checks your code for dubious constructs. Yet another
back end dumps the parse tree back out as Perl source, acting as a
source code beautifier or deobfuscator.
=====

С этими бекендами можно делать забавные штуки - получать
декомпилированные исходники (как показал Алекс), смотреть сам опкод, и
т.д., подробнее см. perlcompile.

Хотелось бы услышать от уважаемых участников, что еще в практическом
плане можно извлечь из -MO сотоварищи.

Ссылки по теме:
http://search.cpan.org/~rgarcia/perl-5.10.0/ext/B/O.pm
http://search.cpan.org/~rgarcia/perl-5.10.0/ext/B/B/Deparse.pm
http://search.cpan.org/~rgarcia/perl-5.10.0/pod/perlcompile.pod

--


>  while (1) {
>      ();
>  }
>
>  Кстати, та же фигня с while(" ").
>
>
>  > P.S. Моя логика, как всегда далека от perl, но мне кажется, что эта
>  > запись ближе к
>  > while('') {}
>  > чем к
>  > while(1) {}
>
>
> И ещё ближе к синтаксической ошибке, как в случае с if () {}
>  :)
>
> ______________________________________________________________________
>  Moscow.pm mailing list
>  moscow-pm на pm.org | http://moscow.pm.org
>  http://mail.pm.org/mailman/listinfo/moscow-pm


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