in reply to Re^3: Double Variables
in thread Double Variables

Hi, sorry it took me a while to get it together but I provided a link to what I'm currently trying to do along with the code. The link is New Language Form If no new language file name is entered it just updates the current one. Its part of another project I'm doing and yes, I'm in need of much direction...doing the best I can with what little I know

#! /usr/bin/perl -w use warnings; use strict; use CGI; use CGI::Carp qw ( fatalsToBrowser ); use DB_File; use Fcntl; use File::Basename; print "Content-Type:text/html\n\n"; ######################open the settings file my $query = new CGI; my $status = $query->param("status"); my $lgfilename = $query->param("lgfilename"); my %sts; my $settingsfile="$ENV{'DOCUMENT_ROOT'}/cgi-bin/test/ex/settings/setti +ngs.txt";# tie %sts hash to settings file in settings.txt tie (%sts, "DB_File", $settingsfile) or die "Can't open $settingsfile: + $!\n"; ######################open the language file my $langdir=$sts{'1'}; my %lng; my $lfile="$ENV{'DOCUMENT_ROOT'}/cgi-bin/test/ex/language/$sts{'1'}";# + tie %lng hash to language file in ???language.txt tie (%lng, "DB_File", $lfile) or die "Cant open $lfile: $!\n"; my $count = scalar keys %lng; #################### print qq~ <html> <head> <link href="http://teresafbc.org/css/css.css"rel="stylesheet"type="t +ext/css"> <title>$lng{'19'}</title> </head> <body> ~; print qq~ <table align="center"border="4px"cellpadding="4px"cellspacing="0px +"> <form method="post"action="makelangfile.pl"> <tr> <td width="100%"colspan="3"> <table width="90%"align="center"border="4px"cellpadding="4px +"cellspacing="0px"> <td width="50%"> <p class="c"> $lng{'1'} <br /> <select onChange="if(this.selectedIndex!=0) self.location=this.options[this.selectedIndex].value"> <option value="" selected>$lng{'12'}</option> ~; #################### ##open the language directory opendir(BBB,"$ENV{'DOCUMENT_ROOT'}/cgi-bin/test/ex/language") or die " +Cant open the language directory $!"; my $filename; while(defined($filename=readdir(BBB))){if($filename =~ /.txt*/){#make +sure file extension is .txt before returning + it removes the dots . +.. my $lcfilename =lc($filename); $filename =~ s/.txt*//g;#remove the ".txt" from the name #my $lcfilename =lc($filename);#make sure all is in lower case $filename =~ s/\b([a-z])(\w+)\b/\u$1$2/g;#change case of first letter- +--http://docstore.mik.ua/orelly/perl/prog3/ch02_08.htm print qq~ <option value="http://teresafbc.org/cgi-bin/test/ex/ +settings.pl?default=$lcfilename">$filename</option> ~; } } closedir(BBB); print qq~ </select> </p> </td><td width="50%"> <p class="c"> $lng{'2'} <br /> <select name="new" onChange="if(this.selectedIndex!=0) self.location=this.options[this.selectedIndex].value"> <option value="" selected>$lng{'12'}</option> ~; #################### ##open the language directory opendir(BBB,"$ENV{'DOCUMENT_ROOT'}/cgi-bin/test/ex/values") or die "Ca +nt open the language directory $!"; my $filename; while(defined($filename=readdir(BBB))){if($filename =~ /.txt*/){#make +sure file extension is .txt before returning + it removes the dots . +.. my $lcfilename =lc($filename); $lcfilename =~ s/.txt*//g;#remove the ".txt" from the name $lcfilename =~ s/\b([a-z])(\w+)\b/\u$1$2/g;#change case of first lette +r---http://docstore.mik.ua/orelly/perl/prog3/ch02_08.htm print qq~ <option value="http://teresafbc.org/cgi-bin/ +test/ex/values/$filename">$lcfilename</option> ~; } } closedir(BBB); print qq~ </select> </p> </td> </table> </td> </tr><tr> <td width="100%"colspan="3"> <p class="t"> $lng{'3'}<br />$lng{'4'} </p> </td> </tr><tr> <td width="50%"> <p class="c"> $lng{'5'}<br />$lng{'10'} <br /><input type="text"name="new_lang"> </p> </td><td width="50%"> <p class="c"> <br />$lng{'6'} <br />$lng{'7'} <br />$lng{'8'} <input type="text"name="addfields"size="1"ma +xlength="2"> </p> </td> </tr><tr> <td width="100%"colspan="2"> <p class="c"> <input type="submit"value="$lng{'11'}" /> </p> </td> </tr> </table> <p class="t"><br /><br /> ~; $lgfilename =~ s/\b([a-z])(\w+)\b/\u$1$2/g; if($status eq "old"){ print qq~ <p class="t"><br /><br /> $lng{'13'}<br /> $lng{'15'} $lgfilename ~; } if($status eq "new"){ print qq~ <p class="t"><br /><br /> $lng{'14'}<br /> $lng{'16'} $lgfilename ~; } print qq~ </p> </form> </body> </html> ~; untie %lng; untie %sts; # Clears buffers, then saves, closes, and unlocks file ##make the new "form-on-the-fly open(AAA,">makelangfile.pl")or die "Cant create newlangform.pl $!"; print AAA"\#! /usr/bin/perl -w\n"; print AAA"use warnings\;\n"; print AAA"use strict\;\n"; print AAA"use CGI\;\n"; print AAA"use CGI::Carp qw ( fatalsToBrowser )\;\n"; print AAA"use DB_File\;\n"; print AAA"use Fcntl\;\n"; print AAA"use File::Basename;\n"; print AAA"print\"Content-Type:text/html\\n\\n\"\;\n"; print AAA"my \$query = new CGI\;\n"; print AAA"my \$existing_lang_file = \$query->param(\"existing_lang_fil +e\")\;\n"; print AAA"my \$new_lang = \$query->param(\"new_lang\")\;\n"; print AAA"my \%sts\;\n"; ##open the settings file print AAA"my \%sts\;\n"; print AAA"my \$settingsfile=\"\$ENV{\'DOCUMENT_ROOT\'}/cgi-bin/test/ex +/settings/settings.txt\"\;\n";# tie %sts hash to settings file in set +tings.txt print AAA"tie (\%sts, \"DB_File\", \$settingsfile) or die \"Cant open +\$settingsfile: \$!\\n\"\;\n"; ##open the language file print AAA"my \%lng\;\n"; print AAA"my \$lngfile=\"\$ENV{\'DOCUMENT_ROOT\'}/cgi-bin/test/ex/lang +uage/\$sts{\'1\'}\"\;\n";# tie %lng hash to language file in ??langua +ge.txt print AAA"tie (\%lng, \"DB_File\", \$lngfile) or die \"Can't open \$ln +gfile: \$!\\n\"\;\n"; #################### print AAA"print qq~\n"; print AAA"<html>\n"; print AAA" <head>\n"; print AAA" <link href=\"http://teresafbc.org/css/css.css\"rel=\"style +sheet\"type=\"text/css\">\n"; print AAA" <title>\$lng{\'19\'}</title>\n"; print AAA" </head>\n"; print AAA" <body>\n"; print AAA" <table align=\"center\"border=\"4px\"cellpadding\"4px\"c +ellspacing=\"0px\">\n"; print AAA" <form method=\"post\"action=\"processlangfile.pl\">\n"; print AAA" <input type=\"hidden\"name=\"existing_lang_file\"value=\ +"\$sts{\'1\'}\">\n"; print AAA" <input type=\"hidden\"name=\"new_lang\"value=\"\$new_lan +g\">\n"; print AAA" <tr>\n"; print AAA" <td>\n"; print AAA" <p class=\"t\">\n"; print AAA" \$lng{'9'}\n"; print AAA" </p>\n"; print AAA" </td>\n"; print AAA" </tr>\n"; ################# for($b=0;$b<$count;$b++){$a=$b+1; #figure how many entries for form ################# #print AAA"print qq~\n"; print AAA" <tr>\n"; print AAA" <td>\n"; print AAA" <p>\n"; print AAA" <br />\$lng{'$a'}<br />\n"; print AAA" <input type=\"text\"name=\"newlang$a\"size=\"150\" +><br /><br />\n"; print AAA" </p>\n"; print AAA" </td>\n"; print AAA" </tr>\n"; #print AAA"~\;\n"; }#end the "count" forloop #print AAA"print qq~\n"; print AAA" <tr>\n"; print AAA" <td>\n"; print AAA" <p class=\"c\">\n"; print AAA" <input type=\"submit\"value=\"\$lng{\'11\'}\">\n +"; print AAA" <p>\n"; print AAA" </td>\n"; print AAA" </tr>\n"; print AAA" </form>\n"; print AAA" </table>\n"; print AAA" </body>\n"; print AAA"</html>\n"; print AAA"~\;\n"; print AAA"untie \%lng\;\n"; print AAA"untie \%sts\;\n"; # Clears buffers, then saves, closes, and +unlocks file close(AAA); ######################Build Final Processing Page open(BBB,">processlangfile.pl") or die "Cant build the processlangfile +.pl file $!"; print BBB"\#! /usr/bin/perl -w\n"; print BBB"use warnings\;\n"; print BBB"use strict\;\n"; print BBB"use CGI\;\n"; print BBB"use CGI::Carp qw ( fatalsToBrowser )\;\n"; print BBB"use DB_File\;\n"; print BBB"use Fcntl\;\n"; print BBB"use File::Basename;\n"; print BBB"my \$query = new CGI\;\n"; print BBB"my \$new_lang = \$query->param(\"new_lang\")\;\n"; for($b=0;$b<$count;$b++){$a=$b+1; #figure how many entries for form print BBB"my \$newlang$a = \$query->param(\"newlang$a\")\;\n"; } ##open the settings file print BBB"my \%sts\;\n"; print BBB"my \$settingsfile=\"\$ENV{\'DOCUMENT_ROOT\'}/cgi-bin/test/ex +/settings/settings.txt\"\;\n";# tie %sts hash to settings file in set +tings.txt print BBB"tie (\%sts, \"DB_File\", \$settingsfile) or die \"Cant open +\$settingsfile: \$!\\n\"\;\n"; ##open the language file print BBB"my \%lng\;\n"; print BBB"my \$lngfile=\"\$ENV{\'DOCUMENT_ROOT\'}/cgi-bin/test/ex/lang +uage/\$sts{\'1\'}\"\;\n";# tie %lng hash to language file in ??langua +ge.txt print BBB"tie (\%lng, \"DB_File\", \$lngfile) or die \"Cant open \$lng +file: \$!\\n\"\;\n"; print BBB"my \$newlanguagefile\;\n"; print BBB"my \$lcnew_lang =lc(\$new_lang)\;\n"; print BBB"\$new_lang =~ s/.txt*//g\;\n";#remove the ".txt" from the na +me print BBB"my \$status\;\n"; print BBB"if(\$new_lang eq \"\"){\n";#make it all lower case print BBB"\$newlanguagefile=\"\$sts{\'1\'}\"\;\n"; print BBB"\$status=\"old\"\;\n"; print BBB"}\n"; print BBB"elsif(\$new_lang ne \"\"){\n"; print BBB"\$newlanguagefile=\"\$new_lang\"\;\n"; print BBB"\$status=\"new\"\;\n"; print BBB"}\n"; ###########################################PRINT OUT THE NEW INFORMATI +ON for($b=0;$b<$count;$b++){$a=$b+1; #figure how many entries for form print BBB"my \$final$a\;\n"; print BBB"if(\$newlang$a ne \"\"){\$final$a=\"\$newlang$a\"\;}\n"; print BBB"elsif(\$newlang$a eq \"\"){\$final$a=\"\$lng{\'$a\'}\"\;}\n" +; } print BBB"untie \%lng\;\n"; # delete any existing language.txt file print BBB"unlink \$lngfile\;\n"; # tie %lng(language) hash to and create db file in color.txt print BBB"tie (\%lng, \"DB_File\", \$lngfile, O_CREAT) or die \"Cant o +pen \$lngfile: \$!\\n\"\;\n"; # (re)evaluate db in language.txt by evaluating key/value pairs in \%l +ng hash as follows\n"; print BBB"\%lng=(\n"; for($b=0;$b<$count;$b++){$a=$b+1; print BBB"\'$a\' => \"\$final$a\",\n"; } print BBB")\;\n"; print BBB"\$newlanguagefile =~ s/.txt*//g\;\n"; print BBB"my \$newlanguagefile=lc(\$newlanguagefile)\;\n"; print BBB"open(EEE,\">values/\$newlanguagefile.txt\")or die\"No Can Do + \$!\"\;\n"; for($b=0;$b<$count;$b++){$a=$b+1; #figure how many entries for form print BBB"print EEE\"\\\$lng{\\\'$a\\\'} = \$final$a\\n\"\;\n"; } print BBB"close(EEE)\;\n"; print BBB"untie \%lng\;\n"; print BBB"untie \%sts\;\n"; # Clears buffers, then saves, closes, and +unlocks file print BBB"print\"Location:newlangform.pl?status=\$status\;lgfilename=\ +$newlanguagefile\\n\\n\"\;\n"; close(BBB);

I'm open for comments/critisizm or anything that will help.