http://www.perlmonks.org?node_id=141151


in reply to hm strange loop for me..

This shouldn't make a difference to how your loop works, but it does make it easier for humans to read. You can replace:

$/ = "\/\/\n";

with:

$/ = "//\n";

Besides from that, your code looks fine, and works perfectly for the sample file you have provided. I suspect what might be happening is somewhere in your file you have the sequence "//\n" at say the end of a line inside a record, when you only really want to catch "//" appearing on a line by itself. You might try $/ = "\n//\n" to force this.

Be aware that you may end up reading an extra "empty" record at the end of your file if the last thing in your file is the input record separator.

Cheers,

Paul Fenwick
Perl Training Australia