Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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.