Help - Search - Member List - Calendar
Full Version: Problems Creating Temporary File
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Dave Adams
This code should work but it does not, any suggestions?

All I need is to create a temporary file to store some data so I can
stuff it into
another application and then trash it. I thought it would be easy.


use utf8;
use IO::Handle;
#use File::Copy;
use File::Temp qw /tempdir tempfile /;
$dir = tempdir (CLEANUP => 1);
($fh, $filename) = tempfile( DIR => $dir);
$template = "STARrequestXXXXXX";
($fh, $filename) = tempfile($template, DIR => $dir, SUFFIX => ".xml");
print "FILENAME: $filenamen";
#$fh->print("FILENAME: $filenamen");
$fh->print(" <?xml version="1.0" encoding="ISO-8859-1"?>n");
$fh->print(" <Root>n");
$fh->print(" <GetSTARXMLInfo/>n");
$fh->print(" <Quit/>n");
$fh->print(" </Root>n");
#copy($filename, "StarRequest.txt");
open (TEMPFILE , $filename) || die "Error: $!n";
while(<TEMPFILE>) {
print $_;
}
$fh->close();
#sleep(10);

John W. Krahn
Dave Adams wrote:
QUOTE
This code should work but it does not, any suggestions?

Yes. Please explain in more detail what exactly "does not work".

John
--
use Perl;
program
fulfillment

Graeme St.Clair
Not to be rude, but as JWK said, "What doesn't work?" Also, mentioning the
Operating System would have been good.

Anyway, on the off-chance it's M$, I tried your script on this my Windows XP
Pro system, and got (with extra new lines):-

FILENAME:
C:DOCUME~1ADMINI~1LOCALS~1TempKGxxRpbcuUSTARrequestaIscUR.xml <== From
your script

Can't unlink file
C:DOCUME~1ADMINI~1LOCALS~1TempKGxxRpbcuU/STARrequestaIscUR.xml:
Permission denied at C:/Perl/lib/File/Temp.pm line 858

Can't remove directory C:DOCUME~1ADMINI~1LOCALS~1TempKGxxRpbcuU:
Directory not empty at C:/Perl/lib/File/Temp.pm line 858

After cleaning up a good deal of residual muck left over from a previous
exercise (thanks for the prompt!) relating to "read-only" and "hidden", I
found that (apparently by design, God help us) Windows leaves folders marked
"read only" even after changing all the files. Sure enough, the temporary
folder KGxxRpbcuU is so marked, and I'm guessing that might be your problem,
although the file has indeed been created, and the whole shooting match can
indeed be deleted manually.

If that's your problem, I have no idea how to solve it short of finding some
way to modify File::Temp and/or Windows. (Well, there's always using some
other OS...)

Sorry this isn't more helpful, rgds, GStC.

PS: also tried it on my ancient Linux RH 6.2 sys, but the Perl was 5_005,
and File::Temp was not installed. In any case, it is sensitive to Perl
level - I saw no point in going further.


----- Original Message -----
From: "Dave Adams" <[Email Removed]>
To: <[Email Removed]>
Sent: Tuesday, July 05, 2005 4:53 PM
Subject: Problems Creating Temporary File


This code should work but it does not, any suggestions?

All I need is to create a temporary file to store some data so I can
stuff it into
another application and then trash it. I thought it would be easy.


use utf8;
use IO::Handle;
#use File::Copy;
use File::Temp qw /tempdir tempfile /;
$dir = tempdir (CLEANUP => 1);
($fh, $filename) = tempfile( DIR => $dir);
$template = "STARrequestXXXXXX";
($fh, $filename) = tempfile($template, DIR => $dir, SUFFIX => ".xml");
print "FILENAME: $filenamen";
#$fh->print("FILENAME: $filenamen");
$fh->print(" <?xml version="1.0" encoding="ISO-8859-1"?>n");
$fh->print(" <Root>n");
$fh->print(" <GetSTARXMLInfo/>n");
$fh->print(" <Quit/>n");
$fh->print(" </Root>n");
#copy($filename, "StarRequest.txt");
open (TEMPFILE , $filename) || die "Error: $!n";
while(<TEMPFILE>) {
print $_;
}
$fh->close();
#sleep(10);

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.