http://qs321.pair.com?node_id=150565

It's fun to use obfu to work on your regex skills...

#!/usr/bin/perl use strict; $_= "Just Another Perl Hacker"; print /(.)n/; s/^([^ ]*) *([^ ]*)/$3 $3/; /\sH(.)(.)/; print $2;/(.)\1.(.)/; print $2,",";print $_;


        - Ace "Two programmers walk into a bar, the third ducks"

Replies are listed 'Best First'.
Solution: Not what you'd expect
by domm (Chaplain) on Mar 09, 2002 at 19:40 UTC
    OK, let's de-obfuscate...
    $_= "Just Another Perl Hacker";
    print /(.)n/;
    That's easey, set $_ to JAPH, and print the first char followed by an 'n', i.e. 'A'.

    s/^([^ ]*) *([^ ]*)/$3 $3/;
    Here you have two capturing parenthenses, but replace with $3, which is undef. So in fact you are removing something of $_. And what are you removing?
    ^([^ ]*)
    Thats, from the beginning of the string, everything that's not a space, until the next space, i.e. 'Just'.
     *([^ ]*)
    This is basically the same regex, removing the next word (i.e. 'Another')

    /\sH(.)(.)/;
    This is no replacement, but a match for the two characters following ' H', that is 'a' and 'c'.

    print $2;
    Print the second match, i.e. 'c'.

    /(.)\1.(.)/;
    Another match, the most tricky in this obuf (IMO).
    Reminder: \1 in a regex is basically the same as $1 outside, i.e. the value found in the first capturing parenthenses.
    So, this matches the first char followed by itself, and saves the char after the next in $2. AS you replaced the first two words with nothing, $_ now looks like (using _ instead of space for clarity) __Perl Hacker, so the regex matches

    __Perl Hacker
    and thus saves 'e' in $2;

    print $2,",";
    Which you print here, followed by a ','.

    print $_;
    Print $_ (BTW, just print would've been enough..), .i.e. ' Perl Hacker'

    Not that hard to de-obfuscate, the only thing that made me wonder what was going on was '\1' in one regex.

    --
    #!/usr/bin/perl -w just another perl hacker
    print+seek(DATA,$=*.3,@-)?~~<DATA>:$:__DATA__