in reply to I try to write script which try to open a text file and read first line from it

There's a mistake in the requirement. If the file does not exist, the opening already fails.

use autodie qw(:all); use Errno qw(ENOENT); use Try::Tiny; try { open my $in_handle, '<', 'textfile'; my $first_line = readline $in_handle; } catch { if (ENOENT == $_->errno) { open my $out_handle, '>', 'statusfile'; print {$out_handle} ('0'); } };
  • Comment on Re: I try to write script which try to open a text file and read first line from it
  • Download Code