While considering this bit of code again:
perl -pe'}{$_=$.' filename
and the implications of the implied continue, I wondered outloud about unobvious pathologies in general. Consider, for your amusement, what this does:
for (qw(Whom the bell tolls)) {} continue { print "$_\n"; next }
[We could argue that this example should produce a warning, but this post is really about enjoying the quirks, and not about fixing them.]

What pathologies twist the corners of your mouth?

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re: Unobvious Pathological Code Snippets
by gaal (Parson) on Mar 28, 2006 at 17:12 UTC
    A recent favorite, noted by Dominus, is that your example could be rewritten as:

    for $t qw(Whom the bell tolls) {} # huh? for qw() ? continue { print "$t\n"; next }

    Update: fixed code, frodo72++

        It's not like this is intended behavior :)

        My other favorite is even sicker and more useful. Credit this time to audreyt++ who checked this into pugs with the commit message

        do not mention $@% in the Makefile for portability

        We had a one-liner that was breaking differently on different platforms. Insane desugaring to the rescue!

        - \$(PERL) -MFile::Spec -e "my (undef, \$\$dir, \$\$file) = File +::Spec->splitpath(shift); chdir(\$\$dir); system(q+$hsc2hs $hsc2hs_fl +ags + . \$\$file);" \$< + \$(PERL) -MFile::Spec -e "sub p () { File::Spec->splitpath(ARG +V->[0]) }; chdir((p)[1]); system(q($hsc2hs), qw($hsc2hs_flags), (p)[2 +]);" \$<
        (The thing to note here is ARGV->[n].)
      Am I missing something? With perl 5.8.8 in linux I get an error:
      poletti@PolettiX:~/sviluppo/perl$ perl pathological.pl Missing $ on loop variable at pathological.pl line 1. poletti@PolettiX:~/sviluppo/perl$ poletti@PolettiX:~/sviluppo/perl$ poletti@PolettiX:~/sviluppo/perl$ cat pathological.pl for qw(Whom the bell tolls) {} # huh? for qw() ? continue { print "$_\n"; next }
      while the OP's example...

      Flavio
      perl -ple'$_=reverse' <<<ti.xittelop@oivalf

      Don't fool yourself.
        Oops, ()-less qw requires a loop variable. Fixed.
Re: Unobvious Pathological Code Snippets
by BrowserUk (Patriarch) on Mar 28, 2006 at 18:11 UTC

    This, (attributable to Juerd) is kinda cute, and a little surprising:

    my @a = '01' .. '30'; print "@$_" for sub{ my $n=shift; map{ [ splice @_, 0, $n ] } 0 .. @_ / $n }->( 5, @a ); 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 print @a; 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 +4 25 26 27 28 29 30

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      <Tim "The Toolman" Taylor>

      Hrruuhhhh???

      </Tim "The Toolman" Taylor>

      While that's devilish and all that, how is it pathological? Heck, it doesn't even DWIM unless $n divides @_.

      The interesting bit, to me, is passing arguments to the anonymous sub.

      I guess I should have stated more explicitly that I'm looking for things that can't be grokked without deep diving into the docs or the source code. For instance, the continue/next behavior is documented, rather humorously, as "entertaining", without being so explicit as to spoil the fun.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        The thing to note is that despite having "destructively" spliced the array into chunks, the array remains unchanged after the process.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Unobvious Pathological Code Snippets
by hv (Prior) on Mar 29, 2006 at 02:07 UTC

    Here's a couple:

    zen% perl -we '$|--; print $|; $|--; print $|; print --$|, --$|, $|- +-, $|--, $/' 100001 zen%

    Hugo