From: <[EMAIL PROTECTED]>
> Hello Jenda,
> 
> I am getting weak on regex.
> 
> Could you please break this down for me        /(.*?-?\d+(?:\.\d+)?)/g
> 
> That is:
> 
> my @last_line = ($report[-1] =~ /(.*?-?\d+(?:\.\d+)?)/g); # split the
> last line into fields (including spaces!)

I'm trying to match each column including the leadning spaces.
The regexp matches as much as necessary of anything followed by a 
number. The

        -?\d+(?:\.\d+)?

matches a number, both positive and negative and both integer and 
float.

Assuming the last line is
1974        9.2      3.4   10.5    8.8   9.7     4.6   13.0      11.5

The regexp first matches "1974", then "        9.2", 
then "      3.4", then "   10.5", ...

I do care about the spaces because I need to find the ends of the 
columns.

(I removed a few spaces to make it fit on one line in mail client.)

> Also, why did you use  $report[-1] instead of $report[$#report]?

They mean the same (not sure if there is any speed difference, but I 
don't think it matters). I just think $report[-1] is cleaner and if I 
ever needed to copy the snippet of code and rename the variable I 
only have to do it once. It's just "the first item from the end" 
instead of "the last element".

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to