Noob question: Is all this typecasting normal?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Jan 5 22:44:18 EST 2009
En Mon, 05 Jan 2009 02:03:26 -0200, Roy Smith <roy at panix.com> escribió:
> The other day, I came upon this gem. It's a bit of perl embedded in a
> Makefile; this makes it even more gnarly because all the $'s get doubled
> to
> hide them from make:
>
> define absmondir
> $(shell perl -e ' \
> sub absmon { my $$a = $$_[0]; \
> if ( $$^O =~ m/cygwin|MSWin32/i ) {
> $$prefix = `/bin/mount -p|awk "NR==2{print \\\$$1}"`;
> chomp($$prefix); \
> $$a = ($$_[1]||"$(PWD)") . "/$$a" \
> unless ( $$a =~ m !^(:?$$prefix|/|[A-Za-z]:)! ); \
> } else { $$a = ($$_[1]||"$(PWD)") . "/$$a" unless ( $$a =~ m !^/! );
> } \
> return unslash(undot(undotdot($$a))); }; \
> sub unslash ($$) { $$_[0] =~ s://+:/:g; $$_[0] =~ s:/$$::;
> return($$_[0]);
> }; \
> sub undot ($$) { $$_[0]=~s:/\./:/:g; return ($$_[0]); }; \
> sub undotdot ($$) { my $$in = $$_[0]; \
> return ( $$in =~ s:/[^/.][^/]*/\.\.::g )?undotdot($$in):$$in; }; \
> print absmon("$(1)","$(2)"); \
> ' )
> endef
>
> Barf-o-rama. I know what it's supposed to do, and I still can't figure
> it out.
Ouch! Me too, when I come to some piece of Perl code I've written some
years ago, I invariably think "what's all this noise?". Never happens with
other languages I've used in the past.
--
Gabriel Genellina
More information about the Python-list
mailing list