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.
In reply to Re: Funny code (not amused)
by Aristotle
in thread Funny code
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |