Help ! Unable to create tmp file using a CGI script

A

Arun

This is the code that I am using to create the file and am
failing.Please help.
thanks

#!/opt/bin/perl -wT
use strict;
use IO::File;

$file = "$ENV{'PWD'}" . "$ENV{'PATH_INFO'}";
$tmp = $file . ".tmp";
$tmp =~ s/\//@/g; # make a unique tmp file name from the path
$tmp = "/tmp/$tmp";

$fh = IO::File->new("> $tmp")
or die "Couldn't open $tmp for writing: $!\n";

while (<STDIN>)
{
if(defined $fh)
{
print $fh "$_\n";
}
}
$fh->close;
 
S

Sherm Pendley

Arun said:
$file = "$ENV{'PWD'}" . "$ENV{'PATH_INFO'}";
$tmp = $file . ".tmp";
$tmp =~ s/\//@/g; # make a unique tmp file name from the path

Wow, two FAQs in three lines of code. That takes talent. :)

Have a look at:

perldoc -q always quoting
perldoc -q temporary
$fh = IO::File->new("> $tmp")
or die "Couldn't open $tmp for writing: $!\n";

Why did you include an error message if you're not going to read what it
prints? The message in $! will tell you why it couldn't open $tmp.

sherm--
 
M

Martin Kissner

Arun wrote :
#!/opt/bin/perl -wT
use strict;
use IO::File;

$file = "$ENV{'PWD'}" . "$ENV{'PATH_INFO'}";
$tmp = $file . ".tmp";
$tmp =~ s/\//@/g; # make a unique tmp file name from the path
$tmp = "/tmp/$tmp";

$fh = IO::File->new("> $tmp")
or die "Couldn't open $tmp for writing: $!\n";
[...]

besides your problem of opening the file:

use strict;
[...]
my file
my tmp
[...]
my $fh
[...]

HTH
 
M

Martin Kissner

Arun wrote :
#!/opt/bin/perl -wT
use strict;
use IO::File;

$file = "$ENV{'PWD'}" . "$ENV{'PATH_INFO'}";
$tmp = $file . ".tmp";
$tmp =~ s/\//@/g; # make a unique tmp file name from the path
$tmp = "/tmp/$tmp";

$fh = IO::File->new("> $tmp")
or die "Couldn't open $tmp for writing: $!\n";
[...]

besides your problem of opening the file:

use strict;
[...]
my $file
my $tmp
[...]
my $fh
[...]

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top