in reply to write to /dev/full does not fail
It does fail, but you need to check for failure.
open, print, and close return a true value upon success, and a false value upon failure. They don't inherently throw an exception. If you want an exception to be thrown, you must test the return values and throw it.
In the case of your code, it's the "close" that returns a failure status. The standard idiom is this:
open my $fh, '>', '/dev/full' or die $!; print $fh "Hello world!\n"; close $fh or die $!;
In this case, the error would be, "No space left on device at mytest.pl line 8.", where line 8 in my code is actually the "close" line.
The autodie pragma would handle this automatically for you. However, in my testing it isn't effective when evoked like this:
perl -mstrict -mautodie -e '..........'
For some reason (which I haven't investigated), one must invoke it like this:
perl -mstrict -e 'use autodie; ........... '
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: write to /dev/full does not fail
by dave_the_m (Monsignor) on May 23, 2014 at 06:37 UTC | |
|
Re^2: write to /dev/full does not fail
by Discipulus (Canon) on May 23, 2014 at 07:44 UTC | |
by choroba (Cardinal) on May 23, 2014 at 07:48 UTC | |
by Discipulus (Canon) on May 23, 2014 at 07:57 UTC | |
by kschwab (Vicar) on May 23, 2014 at 16:34 UTC | |
by kschwab (Vicar) on May 23, 2014 at 16:37 UTC |