Hello
I download a web page that includes data used and remaining data for a mobile connection.
I want to find the two values and convert them from strings to values.
A snippet of the html page is:
<span class="remaining-data">54MB used</span>
<span class="expires-data-right-align">1.44GB remaining</span>
I use the regex to get a matching substring with the 1st value within
(my $DataUsed) = $stgUsed =~ /"remaining-data">([+-]?(\d*\.)?\d+)(MB
+|GB) used/; # trying to get just the digits.
(my $unit) = $stgUsed =~ /(MB|GB)/; # match either MB or GB
if ( $unit eq "GB"){ $DataUsed *= 1000; }
The output in $stgUsed is what I expect:
DB<5> x $stgUsed
0 'class="remaining-data">315MB'
In want to capture just the number (315) and the units (MB) but $DataUsed in undef.
I have tried using $1,$2 ... but they are undef as well.
How to I get the digits substring and the MB/GB substring????
Dazz
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.