in reply to Question on Reading a file inside while and counting no.of lines
Hi vyeddula,
I initialized count to 1
Yes you did.
there is $count++ which it has to make it start from 2
No, with print $count++; you are saying, print the present value of $count, then increase it value by 1.
So if you want the value to start from 2, then increase the value first then print like so:
print ++$count it is called pre-incremental.
Test this:
my $count = 1; while(<DATA>) { print ++$count; print ":$_"; } __DATA__ apple snake cow dog
|
|---|