((($^O=~/^\s*$32/i)&&($0=~s#.*\\##))||($0=~s#.*/##))&&print$0; - nb Nelson Brito

20040818 Edit by ysth: add code tags

Replies are listed 'Best First'.
Re: Funny code (not amused)
by Aristotle (Chancellor) on Aug 18, 2004 at 15:46 UTC

    For anyone who's wondering: it prints the basename of the script it runs in, eg for /home/ap/t.pl it produces t.pl. The $^O stuff is to distinguish DOS vs Unix path separators (backslash vs slash).

    It's not obfuscated at all, just overly dense, and not even really portable (slash works as a path separator on DOS as well; and it will fail on some systems like old MacOS and likely VMS). Here's how it should be done, readably, safely, and portably:

    use File::Spec::Functions qw( rel2abs splitpath ); print +( splitpath rel2abs $0 )[2];

    Or, better yet, if you don't mind loading another module:

    use File::Spec::Functions qw( rel2abs ); use File::Basename; print basename rel2abs $0;

    But placing too much trust in $0 in the first place is a mistake anyway…

    Makeshifts last the longest.

      The $^O stuff is to distinguish DOS vs Unix path separators (backslash vs slash).
      That may be it's purpose, but in fact it is having no effect at all. First the code tries removing everything through the last backslash; if there was no backslash it tries removing everything through the last slash. I still can't tell if the $^O part is intentional obfu or just a typo.

        For the third time, it is a typo, not an attempt at obfuscation. Please don't make me tell you again.

        - tye        

Re: Funny code
by ysth (Canon) on Aug 18, 2004 at 14:15 UTC
    I don't see any obfuscation there, except lack of whitespace and that deceptive $32.