Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: "42" ~~ "42.0" is false in 5.10

by syphilis (Archbishop)
on Dec 24, 2007 at 13:17 UTC ( [id://658885]=note: print w/replies, xml ) Need Help??


in reply to "42" ~~ "42.0" is false in 5.10

IMHO they should be compared as numbers but they are compared as strings

Well ... they *are* both strings ... and you are doing nothing that dictates that those strings should be numified. The behaviour seems totally reasonable to me.

OTOH, "42" * 1 ~~ "42.0" * 1 should (and does) evaluate as true - because, in this instance, something *is* being done to numify the strings.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: "42" ~~ "42.0" is false in 5.10
by tomfahle (Priest) on Jan 24, 2008 at 17:09 UTC

    Hi,

    To me it looks right:

    If it looks like a string, it will be treated as string.

    Here's a small programm to test the new ~~ Operator.

    use strict; use warnings; use 5.010; ## No quotes &test_smartmatch(42, 42); # yields 42 smartmatches 42 &test_smartmatch(42,42.0); # yields 42 smartmatches 42 ## Single Quotes &test_smartmatch(42,'42.0'); # yields 42 smartmatches 42.0 &test_smartmatch('42','42.0'); # yields 42 doesn't smartmatch 42.0 ## Double Quotes &test_smartmatch("42","42.0"); # yields 42 doesn't smartmatch 42.0 ########################################################### sub test_smartmatch { my $lhs = shift @_; # Left Hand Side (LHS) my $rhs = shift @_; # Right Hand Side (RHS) if ( $lhs ~~ $rhs ) { say "$lhs smartmatches $rhs"; } else { say "$lhs doesn't smartmatch $rhs"; } } ## ########################################################### __END__

    Just my 2 cents.

    Hope this helps.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-24 14:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found