Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl-Sensitive Sunglasses
 
PerlMonks  

RE: shortest

by Jeff Connelly (Acolyte)
on Sep 17, 2000 at 02:36 UTC ( [id://32848]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to shortest

31 characters: perl -ne's/./$&&1?o:e/eg;print'

Replies are listed 'Best First'.
Ouch!
by frankus (Priest) on Sep 18, 2000 at 15:10 UTC
    perl -ne's/$&&1?o:e/eg;print'

    Okay this rocks and I've voted for your code... I think this is what's happening :

    1. perl -ne ''executes the one liner forever.
      1. the regexp substitutes each character using s/./ and /g.
      2. $& is the previous matches.
      3. &1 is evaluated in the trinary operator ? using /e.
      4. if &1 then replace with odd else replace with even
    2. print defaults to $_, the results of the regular expression.
    but what I really wanna know is: what is &1?

    Brother Frankus.

      &1 is the logical and applying the bit mask (1). Even numbers always end with a zero bit, odd always end with a 1 bit. This is a simple test for even/odd.
        Yup this I get, now ... how did I get a negative posting for asking a question? Is my appraisal wrong or does someone resent the ZX spectrum colours?

        Brother Frankus.

        Yup this I get, now ... how did I get a negative posting for asking a question? Is my appraisal wrong or does someone resent the spectrum colours?

        Brother Frankus.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://32848]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.