[Pdx-pm] Regex

benh ben.hengst at gmail.com
Mon Feb 6 13:43:32 PST 2012


To pile on with everyone else, you can do the assignment all in one line:

  my ($count,$total) = map{s/,//g;$_} $s =~ m/Usage:([\d,]+) +of +([\d,]+) /

And that begs the larger question, is there a reason why you are both
checking and parsing $info at once? Given the current syntax I think
that even if the line is properly formatted as long as total is 0 then
you'll fail to run the block, is this what you want?  Or do you want
to also run this block given no messages out of a total number of
messages?



On Mon, Feb 6, 2012 at 09:16, Jeff Lavallee <jeff at zeroclue.com> wrote:
>
>
>
> 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
>
> _______________________________________________
> Pdx-pm-list mailing list
> Pdx-pm-list at pm.org
> http://mail.pm.org/mailman/listinfo/pdx-pm-list



-- 
benh~

http://about.notbenh.info


More information about the Pdx-pm-list mailing list