in reply to simple Perl script template

Hi Dumu,

You should check the state of file opening:

open my $fh, '>', $fname or die "Cannot open $fname - $!\n";
Unless Modern::Perl does that. I've never used Modern::Perl.

Update: 'warn' changed to 'die' and '\n' were appended.

Replies are listed 'Best First'.
Re^2: simple Perl script template
by Dumu (Monk) on Apr 09, 2015 at 12:55 UTC
    Modern::Perl basically enables strict, warnings, and features for an appropriately modern version of Perl.
Re^2: simple Perl script template
by marinersk (Priest) on Apr 09, 2015 at 12:14 UTC
    That's an interesting design choice. Why do you want to punish the remaining files (die) just because one of them turns out to be unopenable?
      I like the idea of just warning, in case only one of the files can't be written.
        Hi Dumu, marinersk,

        In case of using 'warn' 'next' should be added to suppress unnecessary error messages (I suppose strictures are on) eg.:

        unless (open my $fh, '>', $fname) { warn "Cannot open $fname - $!\n"; next; }
        In case of error we have to rerun the script after fixing the reason. In this sense there is no difference between 'die' and 'warn' version. But 'die' version is smaller -> "small is beautiful"