Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better IO checks in Perl scripts #53

Open
vinjana opened this issue Jun 18, 2019 · 0 comments
Open

Better IO checks in Perl scripts #53

vinjana opened this issue Jun 18, 2019 · 0 comments

Comments

@vinjana
Copy link
Member

vinjana commented Jun 18, 2019

Instead of

while (my $line = <$fh>) {
    doSomethingWithLine($line);
}

the following paradigm should be used

while (!eof($fh)) {
   my $line = readline($fh);
   if (! defined $line) {
     die "IO Error: $!"
   }
  doSomethingWithLine($line);
}

This correctly recognizes and handles IO errors during the processing (in contrast to the previous simple method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant