Leon Timmermans wrote:
On Mon, Dec 15, 2008 at 5:43 PM, Richard Hainsworth
<rich...@rusrating.ru> wrote:
a) I am fed up with writing something like

open(FP, ">${fname}_out.txt") or die "Cant open ${fname}_out.txt for
writing\n";

The complex definition of the filename is only to show that it has to be
restated identically twice.

my $fh = open '>', $filename, :errorstring("Could not open %file: %error");

It doesn't repeat itself, but still gives the programmer the chance to
add a helpful message.

I assume that the return value of C<open> will be an unthrown exception (via C<fail>) if the file can't be opened. If your failure mode doesn't cause an immediate failure then it would die when used as an IO. The stringification of that failure object would presumably print a useful error message -- and you could override it by handling it yourself.

Reply via email to