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
In reply to Re: write to /dev/full does not fail
by davido
in thread write to /dev/full does not fail
by usv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |