in reply to Find maximum number in text file and copying its full statement in new text file?

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:

while (<F1>) { my ($number) = /^\s*(\d+)/; if (defined $number) { $high_number = $number if $number > $high_number; } }

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:

use strict; use warnings;

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,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,