Sid Devic Sid Devic - 1 year ago 102
Perl Question

Perl parse every number between two values

say I have a string like:


blah blah 32.22200119 blah 33.440049 blah blah 32.25009912 7621.22 blah blah 37


I know that the numbers I want to parse are restricted between 32 and 35, and have at least 4 decimal points. How would I go about parsing out just these long numbers, while ignoring all the other numbers? (The numbers I am attempting to parse happen to be longitudinal coordinates)

Answer Source

Probably something along the lines of...

while ($line =~ /\b(3[2-5]\.\d{4,})\b/g)
{
    print "Found $1\n";
}

That's for a single line. You'll have to loop over multiple lines if needed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download