[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [Fun With Perl] One of those fancy .sig files



I really don't want to go out into the muggy night to hop a subway
home... so I'm procratinating.

On Tue, Jun 08, 1999 at 07:05:14AM +0100, Richard Proctor wrote:
> On Mon 07 Jun, Vicki Brown wrote:
> ># At 12:53 -0800 2/12/99, my co-worker wrote:
> >> I'm not going to actually try to figure this out, but, um:
> >>
> >>
> >> #!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
> >> $^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
> >>  00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
> >> rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
> >>
> >>                                                  ^
> >>                                                  |
> >>                                                  why does it even *see*
> >> the print statement?

$^ = q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;  , 

$0=q,$, , 

($_=$^) =~ y,$/ C-~><@=\n\r,-~$:-u/ #y,d ,

s,(\$.),$1,gee , 

print

Clearer now?  Okay, maybe not...

$^ = q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;  , 

$0 = '$' , 

($_=$^) =~ y|$\/ C-~><@=\n\r|-~$:-u/ #y|d ,

s/(\$.)/$1/gee , 

print


Getting better?  Basically, what's happening is that $^ is being set
to a string of crap.  The $0 thing, will be used later. Then $^ is run
through a character translation...

$ -> -
/ -> ~
  -> $
C -> :
- -> -
~ -> u
> -> /
< -> 
@ -> #
= -> y

And newlines and carriage returns are deleted.

The result is that:

@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >

becomes

#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker$/$0^=q;$^;,$00=q,$0,,($0_=$0^)=~y,$0/$"C-~><@=\n\r,-~$0:-u/$"#y,d,s,(\$0.),$01,gee,print$/

Do a few characters by eye to convince yourself.


This is then run through the s///, matching against any scalar
variable (/\$./).  The /ee is a JAPH favorite.  It means that any
variables matched will be interpolated, then eval'd.

Putting s/(\$.)/print "$1\n"/ge in the place of the s/// shows us what is matched:
$/
$0
$^
$0
$0
$0
$0
$0
$"
$0
$"
$0
$0
$/

Checking their values...
$/ -> '
'
$0 -> '$'
$^ -> '@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >'
$" -> ' '

So, basically its a fancy way of interpolating #!/usr/bin/perl -- Russ
Allbery, Just Another Perl
Hacker$/$0^=q;$^;,$00=q,$0,,($0_=$0^)=~y,$0/$"C-~><@=\n\r,-~$0:-u/$"#y,d,s,(\$0.),$01,gee,print$/
as a double quoted string... kinda, but not really.  The $/ are
replaced by newlines, $0 is replaced by '$', $" is replaced with a
space, $^ with the garbage...

Ultimately, the original string is rebuilt.


Ta da!


-- 

Michael G Schwern                                           schwern@pobox.com
                    http://www.pobox.com/~schwern
     /(?:(?:(1)[.-]?)?\(?(\d{3})\)?[.-]?)?(\d{3})[.-]?(\d{4})(x\d+)?/i


==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org