Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: File handles and loopsby Neighbour (Friar) |
on Jul 31, 2012 at 07:11 UTC ( [id://984578]=note: print w/replies, xml ) | Need Help?? |
In your validate_file sub, you open the file and while looping through the lines, (if something's wrong), close the file and allow it to edit. But what happens after the editing is done? The file is still closed, the while loop will stop (since it can't read from the closed filehandle) it will attempt to close the filehandle again, and return 1. This is not what you intended :) How about something like this (untested)? The initial $file_ok-value seems a bit off, but this is to make sure the while loop triggers at least once :) This method means that validate_file is called once, and will only return when the file is ok. I'm not sure if that's what you intended. You could move the while (not $file_ok)-loop out of validate_file-sub and keep calling the sub while the file is not ok.
In Section
Seekers of Perl Wisdom
|
|