Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Brain Teaser

by marcink (Monk)
on Jun 10, 2001 at 22:59 UTC ( #87338=note: print w/ replies, xml ) Need Help??


in reply to Brain Teaser

Update: added <READMORE> to let others have fun too ;-)

Why does it evaluate to zero
It does not ;-) add a print "\n"; after that and you'll see.

Meaning:
print //; # pattern-match an empty string. result: 1 print \\//; # ref to ref to variable holding 1 (1) print \\\//; # ref to ref to ref to variable holding 1 (2) print \\///\\\//; # print (1) / (2)

Since references return memory addresses when accessed as numbers, the last line will result in some value close to 1, just a little smaller (this is because (1) is allocated before (2)).

Anyway, that's my guess. Anyone care to point my mistakes?

-mk


Comment on Re: Brain Teaser
Select or Download Code
Re: Re: Brain Teaser
by srawls (Friar) on Jun 10, 2001 at 23:10 UTC
    Good job. You even got it after I forgot to write that it only returns 0 in integer context. In normal numeric context it returns something close to .9893410001 depending on your platform and whether or not you call the script from the command line with -e(the command line uses a different memory location).

    The 15 year old, freshman programmer,
    Stephen Rawls

      I looked at the above answer and I'm still not sure why it parses the way it does! Interesting.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar";
      $nysus = $PM . $MCF;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://87338]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2015-07-06 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls