Subject: | Shouldn't croak, it should retun; |
Hello,
neat module! A few things I noticed that make it impractical to use currently:
0) It should maybe not use the bare word file handle to avoid collisions, it could use a lexical var as the handle (not too big
a deal since it is package specific)
1) It should not croak/die it should return; and allow the caller to handle failure.
2) print FILE $with x $bytes; is bad:
a) it assumes $with is one byte (which it is unless they call the internal function, so not too big of a deal)
b) it uses $bytes amount of memory to create the junk data since '$with x $bytes' creates the string in memory before
passing it to the handle (ie.e try to overwrite a 1 GB file == 1 GB of memory used by the script)
A while() or for() with numbered .. range is much more memory efficient:
for (1 .. $bytes) {
print {$fh} $single_byte;
}
You could do fewer iterations with larger chunks but that is currently neither here nor there :)
3) close() is not checked for success (try this as a user who is over their quota. every thing will work fine until close() fails
with over quota errno)
4) in overwrite_and_unlink() you shouldn't do the unlink unless the overwrite returned successfully
HTH :)