Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Sadly goto is a useful construction in C, because the flow control primitives are, well, far more primitive than Perl. For example, you can only break out of the innermost loop.

    Perl's goto has something that isn't offered by C or PHP - goto &NAME [perl.org]. That form is really the only form that anyone should be using in Perl code, and then only when they know what they're doing and why. I don't know PHP, but either it has flow control structures as powerful as Perl's, in which case goto is not needed, or the flow control structures themselves should have been enhanced, rather than adding goto. Either way, what they did is daft.

    Your stats don't line up. You're grepping all files, not just C code initially, and I don't believe that your find commands do what you expect.

    Perl

    $ find perl-5.10.0 -name ext -prune -o '(' -type f -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; | wc -l
    231417
    $ find perl-5.10.0 -name ext -prune -o '(' -type f -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; | egrep '\bgoto\b' | wc -l
    1216
    $ find perl-5.10.0 '(' -type f -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' -or -iname '*.xs' ')' -exec cat {} \; | wc -l
    293114
    $ find perl-5.10.0 '(' -type f -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' -or -iname '*.xs' ')' -exec cat {} \; | egrep '\bgoto\b' | wc -l
    1340

    PHP

    $ find php-5.2.9/win32/ php-5.2.9/Zend/ php-5.2.9/main/ -type f '(' -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; | wc -l
    120833
    $ find php-5.2.9/win32/ php-5.2.9/Zend/ php-5.2.9/main/ -type f '(' -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; | egrep '\bgoto\b' | wc -l
    201
    $ find php-5.2.9 -type f '(' -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; |  wc -l
    783305
    $ find php-5.2.9 -type f '(' -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; | egrep '\bgoto\b'|  wc -l
    11699

    So most of PHP's C gotos are in extensions, whereas most of Perl's are in the core. But what are all those other files in the PHP habouring gotos?

    $ find php-5.2.9 -type f '(' -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -o -print | xargs grep -c goto | grep -v :0
    php-5.2.9/Zend/README.ZEND_VM:1
    php-5.2.9/Zend/zend_language_scanner.l:1
    p hp-5.2.9/Zend/flex.skl:5
    php-5.2.9/Zend/zend_vm_gen.php:12
    php-5.2.9/Zend/Chan geLog:3
    php-5.2.9/ext/pcre/pcrelib/ChangeLog:1
    php-5.2.9/ext/pcre/pcrelib/pcre _printint.src:1
    php-5.2.9/ext/date/lib/parse_date.c.orig:9309
    php-5.2.9/ext/da te/lib/parse_date.re:3
    php-5.2.9/ext/ming/tests/swfaction.phpt:1
    php-5.2.9/ext /ming/tests/swfaction-new.phpt:1
    php-5.2.9/ext/mbstring/oniguruma/HISTORY:1
    ph p-5.2.9/ext/standard/url_scanner_ex.c.orig:103
    php-5.2.9/ext/standard/url_scann er_ex.re:27
    php-5.2.9/ext/standard/var_unserializer.c.orig:185
    php-5.2.9/ext/p do/pdo_sql_parser.c.orig:45
    php-5.2.9/ext/pdo/pdo_sql_parser.re:12
    php-5.2.9/e xt/zlib/tests/bug.tar:187
    php-5.2.9/sapi/thttpd/thttpd_patch:2

    What are .re and .c.orig files?

    • Thanks for providing more accurate (or.. much more accurate) finds

      I also liked the explanation you gave on the use of gotos. I had a discussion about that with a colleague (who is a Python programmer) and we got around to labels and I tried to explain that Perl has label-aware loop commands. That you can last to a label. In PHP, you can continue an amount of loops outside (continue 3 would exit 3 loops above) while apparently in Python you can't do either, only break and loop.

      I guess what I'm saying is that

    • For those who don't use ack, this is exactly the sort of thing ack was designed to do easily.

      find perl-5.10.0 -name ext -prune -o '(' -type f -iname '*.c' -or -iname '*.cpp' -or -iname '*.h' ')' -exec cat {} \; | egrep '\bgoto\b' | wc -l

      is just

      ack --cc --cpp -w goto perl-5.10.0 | wc -l

      --cc means "C source and headers only", --cpp is "C++ source and headers only", -w means "word only".

      Just install CPAN package App::Ack.

      --

      --
      xoa