in reply to data extraction from a variable

andrewr:

I'd just do something like:

my ($variable, $first, $second); $variable = some_data_provider(); if ($variable =~ /: ([0-9.]+) ([0-9.]+)/) { ($first, $second) = ($1, $2); print "Found the values $first and $second!\n"; }

...roboticus

Amusing note: I accidentally left off the / in the </code> tag and got one of those horrible-looking newbie posts. I wonder if the newbies are enclosing code in a pair of <code> tags?

Replies are listed 'Best First'.
Re^2: data extraction from a variable
by ikegami (Patriarch) on Jan 29, 2010 at 04:01 UTC
    Yes, sometimes they screw up the closing tags. But most of the times, they don't use any tags at all.
Re^2: data extraction from a variable
by andrewr (Initiate) on Jan 29, 2010 at 23:23 UTC

    thanks robiticus !!

    I used your suggestion with a minor change as I realised that my example line wasn't a 100% accurate example (oops)

    if ($variable =~ /:\W{1,15}([0-9.]+)\W{1,15}([0-9.]+)/) { ($first, $second) = ($1, $2);

    worked out how to effectively ignore the spaces between everything.

    again many thanks for helping out a PERL newbie.