Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Can anyone figure this out?

by Anonymous Monk
on Jun 04, 2001 at 00:33 UTC ( #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:

    to this:
    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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2023-06-08 22:37 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (35 votes). Check out past polls.