Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Comapring two values of a scalar

by BillKSmith (Monsignor)
on Apr 13, 2013 at 17:47 UTC ( [id://1028541]=note: print w/replies, xml ) Need Help??


in reply to Re: Comapring two values of a scalar
in thread Comapring two values of a scalar

Uner the same assumption, I prefer a regular expression. The Common module will match any valid number. The /e option will do the subtraction. The /r option returns the result without modifying the original string.

use strict; use warnings; use Regexp::Common; my $NUMBER = qr/$RE{num}{real}/; my @array = ('31:15'); print $array[0] =~ s/($NUMBER):($NUMBER)/$1-$2/er;
Bill

Replies are listed 'Best First'.
Re^3: Comapring two values of a scalar
by igelkott (Priest) on Apr 13, 2013 at 22:50 UTC
    Regexp::Common

    While nice and general, this seems a bit heavy for the OP, especially considering the the rather regular examples given. Of course, always nice to see an example of a more general/powerful solution.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2025-12-07 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (85 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.