I'm working on a shareware software review script. All variables passed by my form are rendered ok. What I would like to do is write a file with the user's registration number as the filename. Perl prints $registration ok but fails to use $registration as the filename.
The value of the label in the form = set to 10100001
I want the script to write the file 10100001.txt
Here's what I came up with so far.
Cheers all,
Ton
#!/usr/bin/perl
use CGI qw(:standard);
#use strict;
print header;
$query = new CGI;
$revdir = review;
$registration = $query->param('registration') ¦¦ '(No input)';
$your_name = $query->param('your_name') ¦¦ '(No input)';
$your_message = param('your_message') ¦¦ '(No input)';
use Cwd;
mkdir( $revdir, 0755 );
chdir review;
$registration = $registration . ".txt";
open NWEFH, ">>$registration";
print NWEFH "Review by: " , $your_name,"\n";
print NWEFH $your_message,"\n\n";
close(NWEFH);
My system did not like your broken bar ¦¦, but that may just be keyboard differences.
my $revdir = review; -> review needs to be quoted.
chdir review; -> review needs to be quoted.
Should use 3 param version of open for safety.
Check return codes.
This worked on my ActivePerl WinXP machine from the command line.
[pre]
#!/usr/bin/perl
use CGI qw(:standard);
use strict;
use warnings;print header;
my $query = new CGI;
my $revdir = "review";
my $registration = $query->param('registration') ¦¦ '(No input)';
my $your_name = $query->param('your_name') ¦¦ '(No input)';
my $your_message = param('your_message') ¦¦ '(No input)';
use Cwd;
mkdir( $revdir, 0755 )
or die "Unable to create directory $revdir - $!";
chdir $revdir
or die "Unable to chdir $revdir $!";
$registration = $registration . ".txt";
open NWEFH, ">>", $registration;
or die "Unable to open $registration for output - $!";
print NWEFH "Review by: " , $your_name,"\n";
print NWEFH $your_message,"\n\n";
close(NWEFH);
[/pre]
when I put $registration in the part to open a file it does not work
When I put $registration ="1011234" . ".txt";
just before I try to open the file it works fine.
Thety both look the same to me.
I guess this part is wrong:
open NWEFH, ">>$registration";
Cheers