As a side note, don't use
chop to get rid of newlines. I see this all the time in programs and it makes me cringe. You want to use
chomp.
chomp will only remove the last character if it's a newline. Consider the following "harmless" code:
#!/usr/bin/perl -w
use strict;
while (<DATA>) {
chop;
print "$_\n";
}
__DATA__
this is a test
this is another
You can't see it in the above code, but I deliberately did not hit "Enter" after the last line. I even hit backspace a few times to ensure that there was nothing after the word "another". The result?
this is a test
this is anothe
chop happily removed the "r" in another.
chomp was designed for situations like that and should be used where appropriate.
Cheers,
Ovid