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

Re: eval'ing strange scalar

by jvector (Friar)
on Jan 23, 2009 at 19:43 UTC ( [id://738568]=note: print w/replies, xml ) Need Help??


in reply to eval'ing strange scalar

Perl 5.8.0 on Solaris gives me 3338748. Perl 5.8.6 on Windows gives me 6742212.
5.10.0 on Ubuntu 8.10 gives 451354452 B-) My thanks also to ikegami for the elucidation, but I am left wondering:

- what is it that m// is matching? The null string, presumably... so would that be different on the same machine at different times?

Answer: yes.

victor@pan:~$ perl -e 'print eval(+\//+\//+\//)."\n";' 411098964 victor@pan:~$ perl -e 'print eval(+\//+\//+\//)."\n";' 436080468 victor@pan:~$ perl -e 'print eval(+\//+\//+\//)."\n";' 415780692 victor@pan:~$


This signature was ready by Christmas. Where were you?

Replies are listed 'Best First'.
Re^2: eval'ing strange scalar
by Zarchne (Novice) on Jan 24, 2009 at 04:26 UTC
    Evidently, the // are matching $_, which even though it is undefined is treated as the null string, which happens to match. The \ is also providing a scalar context. Note that the eval is somewhat superfluous, try
    perl -e '$_="."; $r=\-d; print $r, "\n", $r + 0, "\n", $$r, "\n";'
    Also, your perl or OS appears to have address space randomization (security feature); some machines return the same numbers every time.

    It kinda looks to me like 0+\ might be able to distinguish values depending on how they were arrived at.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found