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

Re^6: scanning hash

by Aristotle (Chancellor)
on Aug 02, 2004 at 20:13 UTC ( [id://379411]=note: print w/replies, xml ) Need Help??


in reply to Re^5: scanning hash
in thread scanning hash

To illustrate the point:

$ perl -le '$a = $b = "foo"; print \$a eq \$b ? "true" : "false"' false

The strings are identical, but they're two different strings. The string representations of references to them differ. Are they equal or not? This is a question of semantics that you can't answer without additional context.

Indeed, if we just accept the string representation as the universal measure of equality, then ambrus is right: the empty string and undef are equal, and thus all of my arguing has been moot. However, experience tells me it is a prudent bet to assume that in most situations, undef needs to be treated differently from an empty string.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^7: scanning hash
by ysth (Canon) on Aug 02, 2004 at 20:20 UTC
    I was thinking of something simpler, such as:
    $x = 1.23456; $y = 1.234560000000001; print 0+($x == $y); # prints 0 for me print 0+($x eq $y); # prints 1 for me
    or
    $x = 0; $y = "0";
    Are they equal? Yes and no.

      That is a very similar class of problem, although not exactly the same.

      I was dealing with the question of whether to compare "by reference" or "by value". A typical situation where this is an issue is comparing objects. What is the criterion then, identity or equality? The answer is much less clear than with the strings I used to demonstrate the point, because objects manifest as references by definition.

      Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-03-28 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found