http://qs321.pair.com?node_id=156461

Here's a chance to show off your extensive knowledge of perl arcana and your vast experience debugging barbarous code. The task for this hole is simply to segfault the latest stable version of Perl (v5.6.1) in the fewest number of characters, given the following rules: Bring the pain!
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
(tye)Re: (Golf) Segfault Perl
by tye (Sage) on Apr 03, 2002 at 22:35 UTC
    unpack"p",$^X

    But if I save it to a file called "puke": unpack$0,$0

            - tye (but my friends call me "Tye")
      Drop the quotes to save another character.
      unpack p,$~
      Works on my linux box and my windows machine.

      Using $~ instead of $^X makes it one character shorter.

      perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Re: (Golf) Segfault Perl
by Juerd (Abbot) on Apr 03, 2002 at 22:49 UTC

    #234567 undef a

    Strokes: 7
    Penalty: 8 (win32, openbsd, hp-ux, mac)

    Score: 15

    Update - Does this only segfault on Linux systems? I thought I had a nice score, but the penalties are killing me :)

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

      Then it looks like we're tied:
        
      #23456789 *::=%::=0
      unless, of course, someone can find a well behaving platform for this :)
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

        Ahem.

        $ perl -e '*::=%::=0' Modification of a read-only value attempted at -e line 1. $ perl -v This is perl, version 5.005_02 built for PA-RISC1.1
        Now I don't feel so bad about dinging Juerd. ;-)

        Just call me StrokeReaper.

        Update
        As MeowChow and Chmrr both pointed out, the rules stipulate 5.6.1. No penalty.

        perl -e '*::=%::=0'
        Bus error(coredump)

        perl -e 'undef a'
        Can't modify constant item in undef operator...

        perl -v
        This is perl, v5.6.1 built for IA64.ARCHREV_0-thread-multi
        Binary build 631 provided by Activestate

        I'll let the judges decide whether this was truly a valid test since the HW is still in the experimental stage. (Itanium running HP-UX 11.22)

      Sorry, two-stroke penalty. It doesn't segfault under Win32:

      C:\>perl -e "undef a" Can't modify constant item in undef operator at -e line 1, at EOF Execution of -e aborted due to compilation errors. C:\>perl -v This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 628 provided by ActiveState Tool Corp. http://www.ActiveS +tate.com Built 15:41:05 Jul 4 2001
      I just realized your sig is longer than your golf program. ;-)

      Update
      Sorry Juerd, the penalty is four strokes. No segfault under 5.00502 on HP-UX either:

      $ perl -e 'undef a' Can't modify constant item in undef operator at -e line 1, at EOF Execution of -e aborted due to compilation errors. $ perl -v This is perl, version 5.005_02 built for PA-RISC1.1 Copyright 1987-1998, Larry Wall
      Now I'm starting to feel bad....

      Update 2
      Whoops! The rules did specify 5.6.1. My bad. Just two strokes off, then.

      Sorry, there is another two stroke penalty. It doesn't work on MacPerl! And by "doesn't work" i mean it does work. And by "does work" I mean "doesn't work". Just to clarify it doesn't crash MacPerl, but MacPerl does kick me when I try to run it! Good code though. And by "Good Code" ... :)
      Hmm, this doesn't seem to segfault OpenBSD either.
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
      [11]: perl -e 'undef a' [12]: perl -v This is perl, v5.6.1 built for sun4-solaris
      nice try though :-)
Re: (Golf) Segfault Perl
by ariels (Curate) on Apr 04, 2002 at 12:20 UTC

    Going through perlvar, I found this. It segfaults, depending on how exactly Perl was compiled, and maybe a few more things...

    12345678901234567 perl -e'$^M=1;$x[1<<30]=2'

    Thrill as memory leaks away! Laugh as Perl attempts to recover using a single byte of memory! (Cry if your Perl was compiled without this silly feature.)

      perl -e'$^M=1;$x[1<<30]=2'

      Segfaults without setting $^M too.

      #2345678901 $x[1<<30]=2

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk
      

        Shave another byte: $x[~0/2]=1

        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: (Golf) Segfault Perl
by clintp (Curate) on Apr 03, 2002 at 22:31 UTC
    I don't personally golf, but am curious: does this also preclude signaling? kill 11,$$ isn't too creative or fun.

      Well, for one thing, that won't segfault on Win32. Not on my Win2K box with Activestate's build 628 of 5.6.1, anyway.

      Hmm... good syscall :) I entirely forgot about that, but since it doesn't crash Windows, you do get a two stroke penalty. I think Juerd's will be difficult to beat.
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

      Won't work where SIGSEGV isn't 11. (You could do tricks with %SIG, but that would up the stroke-count.)


      We are using here a powerful strategy of synthesis: wishful thinking. -- The Wizard Book

      kill 11,0 is shorter.

      You could cut down one more character by making it kill 7,0 (a bus error), but that signal number is not as portable to other architectures as 11 (segfault).

(podmaster: golf) Re:Segfault Perl
by PodMaster (Abbot) on Apr 04, 2002 at 08:28 UTC
    (podmaster: evil ;) Re: Print print Japh
    ########123456789
    #################0123456
    perl -e"$#='%.n';print 1"

    Ugh, 16 chars.
    perl -e"print $#='%n',1" is one char shorter, so that's 15.

    $# is not experimental, but it is deprecated.

    This worked for me on redhat/freebsd/Win32 (all)
     

    Look ma', I'm on CPAN.


    ** The Third rule of perl club is a statement of fact: pod is sexy.
Re: (Golf) Segfault Perl
by petral (Curate) on Apr 04, 2002 at 01:07 UTC
    If you want to really get fussy, certain unnamed entries produce bus errors (8a) not segmentation faults (8b), but I'm not going to bring it up.

      p
Re: (Golf) Segfault Perl
by Anarion (Hermit) on Apr 05, 2002 at 10:47 UTC
    anarion@anarion:~/perl$ perl -e'read A,A' Segmentation fault

    This is perl, v5.6.1 built for i386-linux

    $anarion=\$anarion;

    s==q^QBY_^=,$_^=$[x7,print

      +2 strokes
      <tsm:rylesl>|/home/rylesl > perl -e'read A,A' Not enough arguments for read at -e line 1, at EOF Execution of -e aborted due to compilation errors. <tsm:rylesl>|/home/rylesl > perl -v This is perl, v5.6.1 built for aix


      perl -e 'print reverse qw/o b n a e s/;'
      + 2 strokes...
      C:\scripts>perl -e"read A,A" Can't modify constant item in read at -e line 1, at EOF Not enough arguments for read at -e line 1, at EOF Execution of -e aborted due to compilation errors. C:\scripts>perl -v This is perl, v5.6.1 built for MSWin32-x86-multi-thread
Re: (Golf) Segfault Perl
by mem (Acolyte) on Apr 05, 2002 at 07:35 UTC
    perl -e '(d,d)=0'

    That's 7... plus penalties... let'em flow in

      Nice, but so far, I can only get this to segfault linux (neither OpenBSD nor Windows misbehave sufficiently). I suspect this is the same bug as Juerd's "undef a".
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

      admin@heaven:~$ perl -e'(d,d)=0' admin@heaven:~$ perl -v This is perl, v5.6.1 built for i386-freebsd
      2 stroke penalty...

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk
      

        dies on AIX:
        <tsm:rylesl>|/home/rylesl > perl -e'(d,d)=0' Memory fault(coredump) <tsm:rylesl>|/home/rylesl > perl -v This is perl, v5.6.1 built for aix


        perl -e 'print reverse qw/o b n a e s/;'
      [4]: perl -e '(d,d)=0' [5]: perl -v This is perl, v5.6.1 built for sun4-solaris