in reply to extracting number from middle of string
Now, this *is* just test code, right? Note that you're checking every line for this match, but then you print after your while loop completes. You may want to bail once you've hit the match.$out_file = "out1"; open (OUT, "$out_file"); while (<OUT>) { next unless $_; if (/Time: (..):(..):(..)/) { $hours = $1; $mins = $2; $secs = $3; } } close (OUT); print "hours =: $hours";
Give it a shot. It's cool! All the kids are doing it...while (<DATA>) { if ($_ && /Time:\s+(\d+):(\d+):(\d+)/i) { $hours = $1; $mins = $2; $secs = $3; last; } } print "hours =: $hours"; __DATA__ Time: 04:45:12
|
---|