Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
In Perl, if printf() fails, a fatal error will be thrown long before it returns to the caller.
I disagree about printf() errors. With normal file operations, what I said is true. It is almost impossible for a print or printf to "fail" once a local Hard Disk file handle is open. One way would be "File system full", but in that case, a fatal exception is thrown - the calling program won't see that.

Test before posting. Confidently making incorrect statements doesn't help anyone.

#!/usr/bin/env perl use warnings; use strict; my $file = $^O eq 'MSWin32' ? "P:\\foo" : '/tmp/foo/bar'; open my $fh, '>', $file or die "$file: $!"; my $data = "\0" x 2_000_000; print "Writing ", length $data, " bytes to $file\n"; printf $fh "%s", $data or warn "printf: $!"; close $fh or warn "close: $!"; print "Still not fatal\n"; __END__ Windows: Install https://www.ltr-data.se/opencode.html/#ImDisk As Administrator: > imdisk -a -t vm -m P: -s 1M -p "/fs:fat /q /y" > perl write.pl Writing 2000000 bytes to P:\foo printf: No space left on device at write.pl line 9. close: No space left on device at write.pl line 10. Still not fatal > imdisk -D -m P: Linux: $ mkdir -vp /tmp/foo $ sudo mount -t tmpfs -o size=1M,uid=`id -u` tmpfs /tmp/foo $ perl write.pl Writing 2000000 bytes to /tmp/foo/bar printf: No space left on device at write.pl line 9. close: No space left on device at write.pl line 10. Still not fatal $ sudo umount /tmp/foo

In reply to Re^7: looking for feedback on my first script by haukex
in thread looking for feedback on my first script by thirtySeven

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found