Re: Question abount counting the total number of lines and put to an variable?



On 11/29/07, Marco <marco@xxxxxxxxxxxx> wrote:

The code will show 2 line liek below, how can I get the a number "2"
and save to the variable? thanks.

User: ABC
User: DEF

It sounds as if you want to count each print operation. You can do
that if you set a variable to zero before you begin printing:

my $lines = 0;

Then, each time you print a line, you add one to $lines.

print "whatever\n";
$lines++; # add one to $lines

After you've finished printing, $lines will hold the value you need. Is that it?

Cheers!

--Tom Phoenix
Stonehenge Perl Training
.