in reply to Re^5: parsing output of UNIX `who` command (golf)
in thread parsing output of UNIX `who` command

thats the one I was interested in, thanks! The only part that still has me wondering is the extra hanging curly brace:
while(<>){ / /, $;{$`}++ } print $_, $/ ^= "*" for % } # <--- this hanging bit
with no opening curly brace I don't understand why its there. Its even more odd in the golf:
who|perl -ne'/ /,$;{$`}++}{print$_,$/^="*"for%' ^^^^ what?
in any event, thank you very much for the very excellent explanation. I have to go read more about XOR now.... ;) blahblah

Replies are listed 'Best First'.
Re^7: parsing output of UNIX `who` command (golf)
by chargrill (Parson) on Oct 10, 2006 at 00:59 UTC

    Whoops, I dropped the opening brace from my de-golf'ing. I'll correct that above, but also try to explain it a little more explicitly.

    The thing to remember is that the perldoc perlrun entry for -n is applied literally.

    Again from perldoc:

    while (<>) { ... # your program goes here }

    So -n literally puts that code around yours.

    while(<>){ / /, $;{$`}++}{print $_, $/ ^= "*" for % # this line is what # was inside the single qu +otes }

    Literally. The }{ closes the while loop and lets you add extra code outside the while loop. And since -n will always add that extra closing brace, you need to open one. Resulting in:

    while(<>){ / /, $;{$`}++ } { print $_, $/ ^= "*" for % }


    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
      chargrill++! Thank you very much. I didn't realize the -n was literally a while wrap, including parens and all. Now it makes much more sense, and opens up many more possibilities for my one liners. Thanks!
        You'll find more examples of }{ (the eskimo greeting) here.

        It was Abigail who brought it up first, according to the secret operators compilation. Look for "Count the number of lines" in that file.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}