On 2013-02-17 02:30, Tom Christiansen wrote: > However, if hitting EOF is an expected and normal event, you > would not to exit just because you ran out of input. Instead, > you probably just want to exit an input loop. Immediately > afterwards you can then test to see if there was an actual > error that caused the loop to terminate, and act accordingly: > > while (<$handle>) { > # do something with data in $_ > } > if ($!) { > die "unexpected error while reading from $filename: $!"; > } I don't like to show a test of such a global. Only if you already know something went wrong, then you can use the global's value(s). Maybe test $handle->error? -- Ruud perl5.8.8 -MIO::Handle -wle ' open my $fin, "<", "not-there"; $fin->error and print map "$_\n", $!, $^E, $@, $?; ' Invalid argument Invalid argument 0 $ perl5.14.2 -wle ' open my $fin, "<", "not-there"; $fin->error and print map "$_\n", $!, $^E, $@, $?; ' Invalid argument Invalid argument 0 $ perl5.14.2 -wle ' open my $fin, "<", "not-there"; $fin->opened or print map "$_\n", $!, $^E, $@, $?; ' 0 (huh? cleared globals?) $ perl5.14.2 -wle ' open my $fin, "<", "not-there"; $fin->opened or $fin->error and print map "$_\n", $!, $^E, $@, $?; ' Invalid argument Invalid argument 0Thread Previous | Thread Next