There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hello sumathigokul, Your regex m/:(\d+):/ finds a sequence of one or more digits occuring anywhere in the line between two colon characters. But in the text file shown, the only colons occur later in the line. You need something like this:
in which the regex finds a sequence of digits at the beginning of the line, preceeded by zero or more whitespace characters only. Note also that if a match fails (as it does for lines 1, 2, 3, 5, 7, etc.), the variable $number is undefined. Always begin your scripts with:
In this case warnings will alert you to the fact that $number is being used in a numerical comparison when it is undef. Hope that helps,
In reply to Re: Find maximum number in text file and copying its full statement in new text file?
by Athanasius
|
|