At 12:04 PM +0800 12/9/10, bezier wrote:
hi,
   how to get all digit from a file? the file like this:


12091025 test

11 fetches, 589 max parallel, 2.418e+06 bytes, in 60.0213 seconds

219819 mean bytes/connection

0.183268 fetches/sec, 40285.8 bytes/sec

msecs/connect: 18.7797 mean, 21.868 max, 16.3 min

msecs/first-response: 7096.68 mean, 8222.38 max, 5989.19 min

2 bad byte counts

HTTP response codes:

  code 200 -- 11

i


Regular expressions can help.

You can use the pattern (\d+) to extract string of consecutive digits. That is good for integers.

For floating point, you can try (\d*\.\d*), although that matches '.', so you might want to check your result. You can also make the pattern more complex: (\d+\.\d*|\d*\.\d+)

For scientific notation with exponents:

(\d*\.?\d*e[+-]?\d+)

might work.

For better methods, see the advice in 'perldoc -q number "How do I determine whether a scalar is a number/whole/integer/float?"' You may have to add capturing parentheses to those regular expressions to extract the numbers.

If you just want to remove all non-digits from the file, use tr:

tr/0-9//dc;



--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to