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

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

by tomfahle (Priest)
on Jan 24, 2008 at 17:09 UTC ( #664083=note: print w/replies, xml ) Need Help??


in reply to Re: "42" ~~ "42.0" is false in 5.10
in thread "42" ~~ "42.0" is false in 5.10

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://664083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2021-10-21 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?