more useful options | |
PerlMonks |
Re: Extracting string from a fileby sundialsvc4 (Abbot) |
on Nov 12, 2013 at 16:23 UTC ( [id://1062231]=note: print w/replies, xml ) | Need Help?? |
There is, of course, “more than one way to do it,™” but I think that the way that I would do it is to use the /g modifier as discussed in perldoc perlretut. Something like ... (caution... extemporaneous code; your syntax may vary)
First, we ignore any lines outright which do not begin with the proper string ... notice the use of the "^" symbol to anchor to start-of-line, and the backslash-escaping of special symbols that otherwise would be taken as part of (ill-formed) regular expression syntax. Then, “the interesting bits” in the string are groupings of digits-and-decimal-points, so we gather up as many of them as are present anywhere in the line. In so-called “array context,” Perl will return an array containing all of the values found, without using a loop to do so, although we certainly could have done so using so-called “scalar context.” Notice the use of parentheses to indicate a substring that we wish to extract.
In Section
Seekers of Perl Wisdom
|
|