The two nicest perl one-liners I wrote so far:

perl -e'socket S,2,1,0;connect S,pack sa14,2,"\nD\321:\226\231";$/=select S;$|=print"D ! @ARGV\nQ\n";print$/ <S>=~/51.*?^(.*?)^\./sm' flu
Query the DICT server at 209.58.150.153 (miranda.org) for the word you specify as commandline arg, and display the first result. The script is endian-agnostic.

perl -ne '/TEST/and$c=6+print@p;$c-->0?$#p=-print:push(@p,$_)>3&&shift@p'
Prints lines that match /TEST/, the 3 lines before the match and the 6 after. Never prints a line twice (which can easily happen accidently if after a match there's another match 7 liner down). You can adjust the number of preceding / following lines by changing the '3' and '6' in the source.

You can also find these along with two others at my home node.

Replies are listed 'Best First'.
Re: Time to golf
by locked_user mtve (Deacon) on Feb 21, 2003 at 22:35 UTC

    Here is miranda:

    socket S,2,1,0;connect S,pack sa14,2,"\nD\321:\226\231";$/=!print S"D ! @ARGV\nQ\n";print<S>=~/51.*?^(.*?)^\./sm

    Counting your grep at 65 chars, i propose this sligtly cheating 53:

    -n0 "@a[$|.($x-6)..$x+++3]"=~TEST&&print for@a=/.*\n/g

    Also, about your 'ark', will following work?

    perl -pe's/(.* )(.*)/$2+0?$$1=$&:$$1/e'
      Miranda: yours doesn't work - hangs forever because you don't auto-flush. (might be platform-dependent)

      grep: Using your count, mine would be 64 actually.

      In any case, yes what you're doing is majorly cheating. The script should work streaming, and you should use /TEST/ since the pattern is supposed to be replacable

      Other than that however it is fairly nice.

      The ark version certainly works, and beats my original by one char. Unfortunately for you, it inspired me to an even shorter one:

      perl -pe's/(.* )(.*)/-$2?$$1=$&:$$1/e'
      So, your turn again :-)

        Ah, yep, you're right about miranda, i noticed that.

        What regarding to ark, not so easy :)

        -p s/\S*$/-$&?${$`}=$&:${$`}/e