R
Robert TV
Hi ... I'm loosing much hair over this array element removal problem i'm
having. I will describe my setup. I have a web form with a single text box
named "recipient" ... on submit, the data is passed to my delete.pl script.
In the same folder, there is a text file called "addresses.txt" This file
contains the following data:
Gerald Genry|[email protected]
Gerry Smith|[email protected]
Robert TV|[email protected]
Terry Valcourt|[email protected]
Dan Perterson|[email protected]
James Smiley|[email protected]
These are names and email addresses separated by a "|" symbol. Here is the
delete script I have so for that is not functional:
#############
#!/usr/bin/perl
use Fcntl qwDEFAULT :flock);
use CGI::Carp qw(fatalsToBrowser);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
open (ADDRESSES, "<addresses.txt") or die "Can't open file: $!";
@entrys=<ADDRESSES>;
close(ADDRESSES);
foreach $entry (@entrys) {
$count++;
if ($entry eq $form{'recipient'}) {
$count--;
splice(@entrys, $count, 1);
}
}
print @entrys;
exit;
#############
If I type "Terry Valcourt|[email protected]" in the web form and submit,
nothing happens. When @entrys prints, it still contains all entires read
from the text file. It's the same for any name and email address grouping
entered. To match the form input to the array element, I used the "eq"
operator. It is my belief that there is no successful matching because there
is a "\n" at the end of each "$entry". So I thought I might add a "chomp
($entry);" command to the equation that would remove the "\n"s from the end
of each $entry. Below is code with the chomp:
#############
#!/usr/bin/perl
use Fcntl qwDEFAULT :flock);
use CGI::Carp qw(fatalsToBrowser);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
open (ADDRESSES, "<addresses.txt") or die "Can't open file: $!";
@entrys=<ADDRESSES>;
close(ADDRESSES);
foreach $entry (@entrys) {
chomp ($entry);
$count++;
if ($entry eq $form{'recipient'}) {
$count--;
splice(@entrys, $count, 1);
}
}
print @entrys;
exit;
#############
This is where things get REALLY messed up. I go back to the web form and
type "Terry Valcourt|[email protected]" This time when @entrys prints, all
lines of data have been removed except "Dan Perterson|[email protected]" I've
spent hours trying to understand what is going on ... please help me see the
light!
P.S. I know most of you may look at my coding methods and laugh, bear in
mind i'm very new and still learning
Robert
having. I will describe my setup. I have a web form with a single text box
named "recipient" ... on submit, the data is passed to my delete.pl script.
In the same folder, there is a text file called "addresses.txt" This file
contains the following data:
Gerald Genry|[email protected]
Gerry Smith|[email protected]
Robert TV|[email protected]
Terry Valcourt|[email protected]
Dan Perterson|[email protected]
James Smiley|[email protected]
These are names and email addresses separated by a "|" symbol. Here is the
delete script I have so for that is not functional:
#############
#!/usr/bin/perl
use Fcntl qwDEFAULT :flock);
use CGI::Carp qw(fatalsToBrowser);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
open (ADDRESSES, "<addresses.txt") or die "Can't open file: $!";
@entrys=<ADDRESSES>;
close(ADDRESSES);
foreach $entry (@entrys) {
$count++;
if ($entry eq $form{'recipient'}) {
$count--;
splice(@entrys, $count, 1);
}
}
print @entrys;
exit;
#############
If I type "Terry Valcourt|[email protected]" in the web form and submit,
nothing happens. When @entrys prints, it still contains all entires read
from the text file. It's the same for any name and email address grouping
entered. To match the form input to the array element, I used the "eq"
operator. It is my belief that there is no successful matching because there
is a "\n" at the end of each "$entry". So I thought I might add a "chomp
($entry);" command to the equation that would remove the "\n"s from the end
of each $entry. Below is code with the chomp:
#############
#!/usr/bin/perl
use Fcntl qwDEFAULT :flock);
use CGI::Carp qw(fatalsToBrowser);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}
open (ADDRESSES, "<addresses.txt") or die "Can't open file: $!";
@entrys=<ADDRESSES>;
close(ADDRESSES);
foreach $entry (@entrys) {
chomp ($entry);
$count++;
if ($entry eq $form{'recipient'}) {
$count--;
splice(@entrys, $count, 1);
}
}
print @entrys;
exit;
#############
This is where things get REALLY messed up. I go back to the web form and
type "Terry Valcourt|[email protected]" This time when @entrys prints, all
lines of data have been removed except "Dan Perterson|[email protected]" I've
spent hours trying to understand what is going on ... please help me see the
light!
P.S. I know most of you may look at my coding methods and laugh, bear in
mind i'm very new and still learning
Robert