Mega Code Archive

 
Categories / Perl / File
 

Uses die when testing for a successful file open operation

#!/usr/local/bin/perl  unless (open(MYFILE, "file1")) {     die ("cannot open input file file1\n");  }  # if the program gets this far, the file was opened successfully  $line = <MYFILE>;  while ($line ne "") {     print ($line);     $line = <MYFILE>;  }