tmpnam is not a builtin perl function, but is available with use POSIX qw(tmpnam);. You seem to use more control struct than is needed, as if you expect the system to need to retry a few times before giving you a file. It would be best to simply call tmpnam() once in sysopen(FH, POSIX::tmpnam(), O_RDWR|O_CREAT|O_EXCL) or die $!;
You might like to try IO::File:
and you never need to know its name.use IO::File; my $fh = IO::File->new_tmpfile();
Update: Added import list for POSIX.
Update2: Scratched blunder, here is something that gets by tye's astute objection to your idiom:
This depends strongly on lazy evaluation of logical operators.use POSIX; my ($tmpfh, $name); do { $name = POSIX::tmpnam() } until sysopen( $tmpfh, $name, O_RDWR|O_CREAT|O_EXCL) or # if error, then $! !~ m/File exists/ # try again if bad name && die $!; # else die
After Compline,
Zaxo
In reply to Re: do until sysopen()
by Zaxo
in thread do until sysopen()
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |