[Pdx-pm] Regex

Jeff Lavallee jeff at zeroclue.com
Mon Feb 6 09:16:00 PST 2012




On Feb 5, 2012, at 9:40 AM, Brian Kurle wrote:

> You need to do the same thing with the first number to catch the commas if they exist there.
> 
> 
>> if ($info =~ /Usage:([\d,]+)\s+of\s+([\d,]+)\s+messages/)

Once you've got the numbers, you can do something like the following to remove the commas (so you can actually use them as numbers):

    if ($info =~ /Usage:([\d,]+)\s+of\s+([\d,]+)\s+messages/){
        my ( $count, $total ) = ( $1, $2 );
        $count =~ s/,//g;
        $total =~ s/,//g;

        print "total - count: ",$total - $count,"\n";






> On Feb 4, 2012, at 10:59 PM, David E. Wheeler wrote:
> 
>> On Feb 4, 2012, at 10:54 PM, Russell Johnson wrote:
>> 
>>> Usage:524,944 of 1,000,000 messages
>>> 
>>> I need the two numbers. The old line was this:
>>> 
>>> Usage:524944/1000000 messages
>>> 
>>> Which I matched with the following code:
>>> 
>>> if ($info =~ m|Usage\:(\d+)/(\d+) messages|)
>>> 
>>> Further complicating matters is that the first number starts at 0, and counts up, so it won't always have a comma. I need to process the two numbers inside the if construct. 
>> 
>> if ($info =~ /Usage:([\d,]+)\s+of\s+(\d+)\s+messages/) 
>> 
>> HTH,
>> 
>> david
>> _______________________________________________
>> Pdx-pm-list mailing list
>> Pdx-pm-list at pm.org
>> http://mail.pm.org/mailman/listinfo/pdx-pm-list
>> 
> 
> _______________________________________________
> Pdx-pm-list mailing list
> Pdx-pm-list at pm.org
> http://mail.pm.org/mailman/listinfo/pdx-pm-list



More information about the Pdx-pm-list mailing list