Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:26:57+00:00 2026-06-11T20:26:57+00:00

During the process of testing my Perl code using Smart Match(~~) I have faced

  • 0

During the process of testing my Perl code using “Smart Match(~~)” I have faced this problem. Will there be any difference between 42, 42.0, “42.0”, “42”

$var1 = "42";
$var2 = "42.0";
$a = $var1 ~~ $var2;

I am getting $a as 0; which means $var1 and $var2 are not equal.

Please Explain.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:26:59+00:00Added an answer on June 11, 2026 at 8:26 pm

    The smart match operator will “usually do what you want”. Please read this as “not always”.

    42 ~~ 42.0 returns true.

    42 ~~ "42.0" returns true as well: the string is compared to a number, and therefore seen as a number. Ditto for "42" ~~ 42.0.

    "42" ~~ "42.0" returns false: both arguments are strings, and these strings do not compare as “equal”, although their numerical meaning would. You wouldn’t want Perl to view "two" ~~ "two-point-oh" as true.

    A string can be forced to it’s numeric interpretation by adding zero:

    0+"42" ~~ "42.0" returns true again, as the first string is forced to the number 42, and the second follows suit.

    The perldoc perlsyn or perldoc perlop page defines how smart matching works:

           Object  Any       invokes ~~ overloading on $object, or falls back:
           Any     Num       numeric equality         $a == $b
           Num     numish[4] numeric equality         $a == $b
           undef   Any       undefined                !defined($b)
           Any     Any       string equality          $a eq $b
    

    You can see that string equality is the default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

During the process of building software applications, you would start testing what you have
During the process of obfuscating a .NET assembly (using Dotfuscator), I have found myself
i have application who use specific process during running and i want to sample
I'm using WF 3.5 and during the process of spinning up a couple of
I use several custom tools during the build process, mostly code generators for service
I'm using the module simplenews and during the registration process it reads Select the
This is my first time implementing In App Purchases. During development and testing of
I have a .NET infra code running both within the IIS worker process and
I'm testing an internal website built on the Magento storefront. During the checkout process,
I'm using Sysinternals DebugView for debugging/logging during testing, and it's pretty good. However I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.