NiteOwl
03-22-2007, 09:55 PM
I Just don't see what is wrong.
Thanks for looking...
I am trying to add/delete a hash key/value and then display it in a drop down menu.
It works, second time arround.
I will remove the # in test.cgi to add a key/value , then run showhash.
It displays the hash before the change, if i run it again it shows it updated.
Same thing with delete key/value.
data file cattype.txt
%content = ( mobile => "Mobile Home",
single => "Single Family",
modular => "Modular",
condo => "Condo",
featured => "Featured",
cland => "Commercial Land",
cprop => "Commercial",
rland => "Residential Land");
Test CGI :
#!/perl/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";
$newitem = "newvalue";
$newkey = "neykey";
$hashfilename = "cattype";
##################################################
#
# To Test i have been removing the # on the statments in bold
#
#
#
##################################################
require "edithash.pm"; # has add/delete/show hash code
# &deletehash($hashfilename , $newkey);
# &addhash($hashfilename , $newitem, $newkey);
&showhash; # This will display the hash as a dropdown
##################################################
edithash.pm
#######################################################
# Prints Dropdown
#
#
#######################################################
sub showhash {
require "gethashselect.pm";
$showthishash = gethashselect($hashfilename);
print qq~<select name="variable name">~;
print $showthishash;
print qq~</select>~;
}
#######################################################
#######################################################
#
# Add Key and Value to Hash
#
#######################################################
sub addhash {
my $val1=$_[0];
my $Newha****em=$_[1];
my $Newhashkey=$_[2];
my $filename = $val1;
my $fileext = ".txt";
require "settings/system/$filename$fileext";
%Thishash = %content;
if ($Newha****em ne "") {
$Thishash{$Newhashkey} = $Newha****em;
}
open(FILE,">settings/system/$filename$fileext") or &dienice("Couldn't open $filename$fileext: $!");
$linelen = scalar keys(%Thishash);
$count = 0;
if ($linelen eq 0){ print FILE "\%Thishash = \(\"\"\)\;\n"; }
else {
print FILE "\%content = \(";
# $count++;
foreach my $i (keys %Thishash) {
print FILE qq~ $i \=\> \"$Thishash{$i}\"~;
$count++;
if ($count < $linelen) { print FILE "\,\n"; }
#if ($linelen-1 > $i) { print "\,"; }
}
print FILE "\)\;\n";
}
close(FILE);
}
#######################################################
#
# Deletes Key, Value from Hash
#
#######################################################
sub deletehash {
my $val1=$_[0];
my $Newhashkey=$_[1];
my $filename = $val1;
my $fileext = ".txt";
require "settings/system/$filename$fileext";
%Thishash = %content;
if ($Newhashkey ne "") {
delete $Thishash{$Newhashkey};
}
open(FILE,">settings/system/$filename$fileext") or &dienice("Couldn't open $filename$fileext: $!");
$linelen = scalar keys(%Thishash);
$count = 0;
if ($linelen eq 0){ print FILE "\%Thishash = \(\"\"\)\;\n"; }
else {
print FILE "\%content = \(";
# $count++;
foreach my $i (keys %Thishash) {
print FILE qq~ $i \=\> \"$Thishash{$i}\"~;
$count++;
if ($count < $linelen) { print FILE "\,\n"; }
#if ($linelen-1 > $i) { print "\,"; }
}
print FILE "\)\;\n";
}
close(FILE);
}
83;
gethashselect.pm
##########################################
# Get Hash Select
# Returns Dropdown Menu
#
# $Var = gethashselect(cattype);
#
##########################################
sub gethashselect {
$selectdata = "";
$selectfile="";
$selecttype="";
$selectfile=$_[0];
%hashdata = ();
##########################################
# Main Logic
##########################################
%hashdata = &loadhash($selectfile);
&loadselectdata;
return ($selectdata);
##########################################
# End Main Logic
##########################################
##########################################
# Get Array from file
#%hashdata = &loadhash($Filename);
#########################################
sub loadhash {
my $filename=$_[0];
my $fileext = ".txt";
require "settings/system/$filename$fileext";
return(%content);
}
##########################################
##########################################
# Create Dropdown menu
##########################################
sub loadselectdata {
foreach my $i (keys %hashdata) {
chomp($hashdata{$i});
$selectdata=$selectdata."\<option Value=\"$i\">$hashdata{$i} \n";
}
}
##########################################
} #end getselect
78;
Thank you for your time...
Thanks for looking...
I am trying to add/delete a hash key/value and then display it in a drop down menu.
It works, second time arround.
I will remove the # in test.cgi to add a key/value , then run showhash.
It displays the hash before the change, if i run it again it shows it updated.
Same thing with delete key/value.
data file cattype.txt
%content = ( mobile => "Mobile Home",
single => "Single Family",
modular => "Modular",
condo => "Condo",
featured => "Featured",
cland => "Commercial Land",
cprop => "Commercial",
rland => "Residential Land");
Test CGI :
#!/perl/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";
$newitem = "newvalue";
$newkey = "neykey";
$hashfilename = "cattype";
##################################################
#
# To Test i have been removing the # on the statments in bold
#
#
#
##################################################
require "edithash.pm"; # has add/delete/show hash code
# &deletehash($hashfilename , $newkey);
# &addhash($hashfilename , $newitem, $newkey);
&showhash; # This will display the hash as a dropdown
##################################################
edithash.pm
#######################################################
# Prints Dropdown
#
#
#######################################################
sub showhash {
require "gethashselect.pm";
$showthishash = gethashselect($hashfilename);
print qq~<select name="variable name">~;
print $showthishash;
print qq~</select>~;
}
#######################################################
#######################################################
#
# Add Key and Value to Hash
#
#######################################################
sub addhash {
my $val1=$_[0];
my $Newha****em=$_[1];
my $Newhashkey=$_[2];
my $filename = $val1;
my $fileext = ".txt";
require "settings/system/$filename$fileext";
%Thishash = %content;
if ($Newha****em ne "") {
$Thishash{$Newhashkey} = $Newha****em;
}
open(FILE,">settings/system/$filename$fileext") or &dienice("Couldn't open $filename$fileext: $!");
$linelen = scalar keys(%Thishash);
$count = 0;
if ($linelen eq 0){ print FILE "\%Thishash = \(\"\"\)\;\n"; }
else {
print FILE "\%content = \(";
# $count++;
foreach my $i (keys %Thishash) {
print FILE qq~ $i \=\> \"$Thishash{$i}\"~;
$count++;
if ($count < $linelen) { print FILE "\,\n"; }
#if ($linelen-1 > $i) { print "\,"; }
}
print FILE "\)\;\n";
}
close(FILE);
}
#######################################################
#
# Deletes Key, Value from Hash
#
#######################################################
sub deletehash {
my $val1=$_[0];
my $Newhashkey=$_[1];
my $filename = $val1;
my $fileext = ".txt";
require "settings/system/$filename$fileext";
%Thishash = %content;
if ($Newhashkey ne "") {
delete $Thishash{$Newhashkey};
}
open(FILE,">settings/system/$filename$fileext") or &dienice("Couldn't open $filename$fileext: $!");
$linelen = scalar keys(%Thishash);
$count = 0;
if ($linelen eq 0){ print FILE "\%Thishash = \(\"\"\)\;\n"; }
else {
print FILE "\%content = \(";
# $count++;
foreach my $i (keys %Thishash) {
print FILE qq~ $i \=\> \"$Thishash{$i}\"~;
$count++;
if ($count < $linelen) { print FILE "\,\n"; }
#if ($linelen-1 > $i) { print "\,"; }
}
print FILE "\)\;\n";
}
close(FILE);
}
83;
gethashselect.pm
##########################################
# Get Hash Select
# Returns Dropdown Menu
#
# $Var = gethashselect(cattype);
#
##########################################
sub gethashselect {
$selectdata = "";
$selectfile="";
$selecttype="";
$selectfile=$_[0];
%hashdata = ();
##########################################
# Main Logic
##########################################
%hashdata = &loadhash($selectfile);
&loadselectdata;
return ($selectdata);
##########################################
# End Main Logic
##########################################
##########################################
# Get Array from file
#%hashdata = &loadhash($Filename);
#########################################
sub loadhash {
my $filename=$_[0];
my $fileext = ".txt";
require "settings/system/$filename$fileext";
return(%content);
}
##########################################
##########################################
# Create Dropdown menu
##########################################
sub loadselectdata {
foreach my $i (keys %hashdata) {
chomp($hashdata{$i});
$selectdata=$selectdata."\<option Value=\"$i\">$hashdata{$i} \n";
}
}
##########################################
} #end getselect
78;
Thank you for your time...