Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Comapring two values of a scalar

by BillKSmith (Chaplain)
on Apr 13, 2013 at 17:47 UTC ( #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;

Comment on Re^2: Comapring two values of a scalar
Download Code
Re^3: Comapring two values of a scalar
by igelkott (Curate) on Apr 13, 2013 at 22:50 UTC

    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?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-03-01 20:00 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (15 votes), past polls