
nezumi
Deleted
Mar 8, 2001, 10:45 AM
Post #1 of 7
(812 views)
|
|
Required help with require...
|
Can't Post
|
|
Hello, This is my problem: I made a main program that uses another with requiere. In the main program I declare #!/usr/bin/perl -w require "libraries.pl"; use strict; use DBI; my $DataBase = DBI->connect("dbi:Pg:dbname=datos", "pepe", "123"); print &DBIDROPMENU("Areas", "areas, "id", "name", "Select One"); exit; ---- The libraries.pl program conteins. #!/usr/bin/perl -w sub DBIDROPMENU { my ($Field, $Table, $Value, $Name, $First, $Selected) = @_; my $ThisSQL="SELECT $Value, $Name "; $ThisSQL.="FROM $Table "; $ThisSQL.="ORDER BY $Name "; my @Registros; @Registros=&DBSELECT($ThisSQL); my $DropMenu="<SELECT NAME=\"$Field\">\n"; if ($First) { $DropMenu.=" <OPTION VALUE=\"\">$First"; } for my $J ( 0 .. $#Registros ) { if ($Selected eq $Registros[$J]{$Value}) { $DropMenu.=" <OPTION VALUE=\"$Registros[$J]{$Value}\" Selected>$Registros[$J]{$Name}\n"; } else { $DropMenu.=" <OPTION VALUE=\"$Registros[$J]{$Value}\">$Registros[$J]{$Name}\n"; } } $DropMenu.="</SELECT>\n"; return $DropMenu; } 1; ------ Of course de DBIDROPMENU gives a full SELECT tag with a given table, value, name, etc. The idea is to put this function in a library file so I could use it anywhere. When I trie to run this the program runs correctly but doesn't return the select tag properly, It only works if I put the function in the same main program... Obviusly the problem is the that the sub in the other program doesn't sees the variable $DataBase of the main. How can I solve this, when I need the to declare the $DataBase variable in any main program and using it in the same libraries.pl??? Thank you for your help.... PD. Sorry for my english, I have a broken arm
|