in reply to Unable to concatinate a Path to the array elements, which will have the values as return values from sunroutine

The line:

while(chomp($line=<F>)) {

has a bug. The chomp function does not return the string which has been chomped; it returns the number of characters removed. So, if the last line in the file does not end in a newline character, chomp returns zero, the while loop terminates, and the last line of data is lost. If the last line does end in a newline character, the last line is processed but the loop doesn’t terminate, so on the next iteration chomp is called on a value of undef, which results in a warning if use warnings; is in effect. The correct approach is:

while ($line = <F>) { chomp $line; ...

BTW, you do always begin your scripts with:

use strict; use warnings;

don’t you?

Hope that helps,

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

  • Comment on Re: Unable to concatenate a Path to the array elements, which will have the values as return values from subroutine
  • Select or Download Code