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

  • Home
  • SEARCH
  • 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 3937650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:05:36+00:00 2026-05-20T00:05:36+00:00

OK, as a preface this question potentially is ‘stupider’ than my normal level of

  • 0

OK, as a preface this question potentially is ‘stupider’ than my normal level of question – however this problem has been annoying me for the last few days so I’ll ask it anyway. I’ll give a mock example of what my problem is so I can hope to generalize it to my current problem.

#!/usr/bin/perl -w use strict;

use Test::More 'no_plan';

my $fruit_string = 'Apples cost $1.50';
my ($fruit, $price) = $fruit_string =~ /(\w+)s cost \$(\d+\.\d+)/;

# $price += 0; # Uncomment for Great Success
is ($price, 1.50, 'Great Success');

Now when this is run I get the message

#   Failed test 'Great Success'
#          got: '1.50'
#     expected: '1.5'

To make the test work – I either uncomment the commented line, or use is ($price, '1.50', 'Great Success'). Both options do not work for me – I’m testing a huge amount of nested data using Test::Deep and cmp_deeply. My question is, how can you extract a double from a regexp then use it immediately as a double – or if there is a better way altogether let me know – and feel free to tell me to take up gardening or something lol, learning Perl is hard.

  • 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-05-20T00:05:37+00:00Added an answer on May 20, 2026 at 12:05 am

    You’re already using Test::Deep, so you can simply use the num() wrapper to perform a numerical rather than stringwise comparison (it even lets you add in a tolerance, for comparing two inexact floating point values):

    cmp_deeply(
        $result,
        {
            foo         => 'foo',
            bar         => 'blah',
            quantity    => 3,
            price       => num(1.5),
        },
        'result hash is correct',
    );
    

    For normal comparisons done separately, cmp_ok will work, but num() is still available: cmp_deeply($value, num(1.5), 'test name') still works.

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

Sidebar

Related Questions

Let me preface this question by saying I use TextMate on Mac OSX for
I will preface this question by saying, I do not think it is solvable.
I'll preface this question by saying this is for a Microsoft only shop. If
First off, let me preface this question by stating that I'm really a pretty
Let me preface this by saying I'm a complete amateur when it comes to
I'll preface this by saying that I usually work in C#/.Net. Normally, I use
I should preface this by saying I'm working on a pocket PC app and
I have to preface this with the fact that I love jQuery as a
Alright, I'll preface this with the fact that I'm a GTK and Python newb,
To preface I am using Borland C++ and the VCL. I need some sort

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.