Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Can anyone figure this out?

by Anonymous Monk
on Jun 04, 2001 at 00:33 UTC ( [id://85369]=obfuscated: print w/replies, xml ) Need Help??

Here's a subroutine I made to find the total number of digits in a string(sounds simple, but very obsfucated, to say the least). Can anyone figure out how/why it works? Here it is:
sub findAllDigits { $_=pop;s;\d;($&&~433)x$&>4?2:$&;geese}; }

Replies are listed 'Best First'.
Re: Can anyone figure this out?
by chipmunk (Parson) on Jun 04, 2001 at 06:35 UTC
    It turns out that this is as simple as it sounds. s///g returns the number of matches found. The replacement in the substitution here is entirely irrelevant, as are the three /e modifiers.

    The subroutine could be rewritten as:

    sub { $_ = pop; s/\d//g; }
    It took me a little while to figure it out, though. :)
Re: Can anyone figure this out?
by srawls (Friar) on Jun 04, 2001 at 01:12 UTC
    Note: you had a type, take off the { and ; and it will work.

    Well, I'll leave it to someone else to explain it, but I'll give you some tips to improve your obfu.

    1. Use as few parentheses as possible: when you write ($&&~433)x ... you don't need those parentheses. It makes it harder to understand if you use as few parentheses as possible, I suggest you scan the precedence table while you are writing your obfu.

    2. your $test:$one?$two is a little easy to understand. I would change your:

    ($&&~433)x$&>4?2:$&
    to this:
    $&&~433x$&>4*$^F+(!$&>4*$&)
    Note I also used one of perl's special variables ($^F) instead of the number 2.

    The 15 year old, freshman programmer,
    Stephen Rawls
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://85369]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-26 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found