Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

The beauty that is perl.

by BUU (Prior)
on Apr 03, 2004 at 23:44 UTC ( [id://342378]=perlmeditation: print w/replies, xml ) Need Help??

Study the following lines:
  1. $"='bar'; print "'$"'";
  2. $"='bar'; print "'$\"'";
  3. $;='bar'; print "'$\;'";
  4. $; = "bar"; print qq;'$\;';;
    (Credit to bart for this example)
Can you guess what each is going to print before you run it?

Replies are listed 'Best First'.
Re: The beauty that is perl.
by demerphq (Chancellor) on Apr 04, 2004 at 09:40 UTC

    Can you guess what each is going to print before you run it?

    Its unlikely many will that dont already know of this bug. I certainly didn't. And im pretty sure this is a bug and in my eyes not in the slightest bit beautiful. For those that want this spelled out. (Update: actually maybe it isnt a bug, suprising as hell, but not a bug.)


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      One practical consequence of this is that you can't "escape" some delimiters to match literally, e.g.: m$\$$ will treat $ as the end-of-line assertion (or as variable interpolation if $ is followed by an identifier), but there's no way to get it to match '$'.

        But that's ok, as you can still use \x24, or even \N{DOLLAR SIGN} after use charnames ":full";.

        Imo, if you want to match a literal dollar sign in the regexp, you just should not use a dollar sign if you want to match a literal dollar sign. That's the same thing as /^\/usr\/bin\//-like regexps, or even worse.

Re: The beauty that is perl.
by flyingmoose (Priest) on Apr 04, 2004 at 00:20 UTC
    Can you guess what each is going to print before you run it?
    No. I can hardly read them.

    Reminds me of something in the back of the ol' campus newspaper. Find the comma:

    ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..,.................................................. .....................................................

      I'm almost embarrassed to say that it actually took me about 30 seconds to locate the comma. *Invents the "find the small L" gimmick*:

      1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 111111111111111111111111111111l111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111 1111111111111111111111111111111111111111
        CTRL+F, one el one ENTER

        About 2 seconds :)

        cLive ;-)

        5,30 in around 10 seconds:)


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
      CTRL + PLUS(+) + PLUS(+) + PLUS(+) +PLUS(+)

      I like Fire(\w+) :)

      cLive ;-)

Re: The beauty that is perl.
by dragonchild (Archbishop) on Apr 04, 2004 at 01:19 UTC
    I'm not seeing the beauty. This looks like obfu to me ...

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      There are so many kinds of beauty in Obfu:
    • the Satori of understanding.
    • the pleasure of code well-obfuscated
    • the appreciation of the fact that, while Perl can be terrifyingly hairy and complex viewed one way, it is rarely so from the perspective of everyday programming.

      Free your mind, man!

        Yes, there are many kinds of beauty in Obfu, and you have listed three of the main ones. However, beauty is still always in the eye of the beholder. That I do not find it beautiful says nothing of its beauty in your eyes. Nor, does it say anything about my capability to see beauty in other things.

        And, I do find many obfus beautiful. Camels by Enlil, for example. My point here was that there was neither obfu nor beauty. To me, the title should have been "Look at this cool stuff!" I have no problem with BUU's meditation, just its title.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      Heh, to be honest the "beauty" was mostly sarcasm =].

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://342378]
Approved by bart
Front-paged by exussum0
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found