M
Mark Constant
I have pre-made code that deletes a line from a flat file database. I
am trying to pass an argument through a link to give the name of the
line to delete.
Here is my database.txt
image020.jpg | 6/4/2004 | 10:19:59 | | rena
Here is how I use the link
delete.cgi?filedelete=$filename
Now here is what prints out
image020.jpg
File image020.jpg not found!
It is obvious that it is grabbing the argument because it prints out
image020.jpg. The thing I don't understand is why it is not matching
with the image020.jpg in the database.txt.
Here is my code
#!c:/perl/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header, $q->start_html('Delete File');
my $action = new CGI;
my @temp=split(/=/,$ENV{'QUERY_STRING'});
my $filedelete = $temp[1];
my $file = 'C:/Program Files/Apache
Group/Apache2/htdocs/quickbooks/database.txt';
my $found = undef;
my (@ary);
my $line;
open( OLD, $file ) or die "Couldn't open old file $file: $! \n";
print $temp[1];
foreach $line (@ary) {
chomp($line);
(my $filename, my $filedate, my $filetime, my $notes, my $user) =
split(/\|/,$line);
push( @ary, $line ) unless ( $filedelete eq $filename );
$found = 1 if ( $filedelete eq $filename );
}
close OLD or die "Couldn't close old file $file: $! \n";
unless ($found) {
print $action->h2("File $filedelete not found!");
exit;
}
open( NEW, ">$file" ) or die "Couldn't open new file $file: $!\n";
foreach (@ary) {
print NEW $_, "\n"
}
close NEW or "Couldn't close new file $file: $! \n";;
exit;
print $q->end_html;
am trying to pass an argument through a link to give the name of the
line to delete.
Here is my database.txt
image020.jpg | 6/4/2004 | 10:19:59 | | rena
Here is how I use the link
delete.cgi?filedelete=$filename
Now here is what prints out
image020.jpg
File image020.jpg not found!
It is obvious that it is grabbing the argument because it prints out
image020.jpg. The thing I don't understand is why it is not matching
with the image020.jpg in the database.txt.
Here is my code
#!c:/perl/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = new CGI;
print $q->header, $q->start_html('Delete File');
my $action = new CGI;
my @temp=split(/=/,$ENV{'QUERY_STRING'});
my $filedelete = $temp[1];
my $file = 'C:/Program Files/Apache
Group/Apache2/htdocs/quickbooks/database.txt';
my $found = undef;
my (@ary);
my $line;
open( OLD, $file ) or die "Couldn't open old file $file: $! \n";
print $temp[1];
foreach $line (@ary) {
chomp($line);
(my $filename, my $filedate, my $filetime, my $notes, my $user) =
split(/\|/,$line);
push( @ary, $line ) unless ( $filedelete eq $filename );
$found = 1 if ( $filedelete eq $filename );
}
close OLD or die "Couldn't close old file $file: $! \n";
unless ($found) {
print $action->h2("File $filedelete not found!");
exit;
}
open( NEW, ">$file" ) or die "Couldn't open new file $file: $!\n";
foreach (@ary) {
print NEW $_, "\n"
}
close NEW or "Couldn't close new file $file: $! \n";;
exit;
print $q->end_html;