in reply to small is beautiful

Hello Shltn

Will you please Explain the above Code.

Replies are listed 'Best First'.
Re^2: small is beautiful
by sh1tn (Priest) on Feb 26, 2005 at 16:06 UTC
    $_->{$.} # $_ becomes reference to hash # $_ returns HASH(memory address) s:.?(.)..(.): # regex which "captures" 2nd 'A' and 5th '(' symb +ols # '..' range operator returns # ABCDEFGHIJKLMNOPQRSTUVWXYZ # from 'A' to '(' # see perldoc perlop print # 'Prints a string or a list of strings' (($1..$2)[9,0,15,7]) # only 9,0,15,7 array elements are interesting :e # /e modifier which evaluates right side # as an expression


Re^2: small is beautiful
by Taulmarill (Deacon) on Feb 26, 2005 at 13:11 UTC
    i'm not 100% shure, but i'll try to explain afaik.
    $_->{$.}
    this only makes $_ a reference to a hash. when accessing $_ via scalar context (as the folloing regex does) you get something like "HASH(0x814cc20)".
    s:.?(.)..(.):print(($1..$2)[9,0,15,7]):e
    this is just a regex substitution with a bit of perlcode in it (the "e" at the end says perl to "Evaluate the right side as an expression.").
    ok, the left side captures "A" and "(" from the string given from a hashref in scalar context (remember?). now the right side generates a list by "A" .. "(" which seems to "realy" generate a list from "A" to "Z" (is this documented somewhere?). from this list the elemnts "[9,0,15,7]" are given to print. thats it!
    easy, hu?