[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Sheflug] Unique temporary filename
>>>>> "Peter" == Peter Duffy <Peter.Duffy [at] supanet.net.uk> writes:
Peter> On Wed, 2002-05-15 at 15:44, David Morris wrote:
>> The Camel book doesn't mention a mktemp though... isn't that
>> part of the C runtime (says he dredging the outermost reaches
>> of his feeble mind)?
Peter> It's just a Linux system command (I was going to say Unix,
Peter> but I don't know how many other Unixen have it.) Try "man
Peter> mktemp". From perl, you'd probably do something on the
Peter> lines of: 'retcode=system("mktemp <arguments>")' and then
Peter> check $retcode to see that it worked.
Well, almost...if you want to really check system, fork and the like:
system($command, @args) == 0 or warn "Doh!: $!";
my $rc = $?;
my $exit_value = $rc >> 8;
my $signal_num = $rc & 127;
my $dumped_core = $rc & 128;
Or if you just want the return code:
my $exit_value = $rc / 256;
I know of one or two programs that'll dump core, yet return a 0 status
and touch the output file - you really do have to check all this lot.
I don't like those programs very much :-)
See perldoc -f system
Also, what's the point in forking a child to make a filename using a
command that may or may not be present on whatever platform you're
running, when it's pretty quick to do it in Perl?
Cheers.
Baz.
--
Barrie J. Bremner OpenPGP public key ID: F78CEE08
baz [at] barriebremner.com http://barriebremner.com/
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.