Skip to content

Better IO checks in Perl scripts #53

Open
@vinjana

Description

@vinjana

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions