Hi Nora, On Friday 29 October 2010 07:23:13 HACKER Nora wrote: > Hello, > > In the below code I am desperately trying to accomplish the valid use of > variable variable names but still fail. I have already read many sites, > tutorials, mailing list posts, all saying that this is best accomplished > by using a hash. Please would you tell me if I understood that correctly > and, even more important, if I interpreted and tried to realize it > correctly? And if someone could tell me why the script gives me errors and > what to change to make it work, that would be great :-) > > CODE: > > #!/usr/bin/perl > use strict; > use warnings; > use DBI; > use DBD::Oracle; > > my $DBI; > my $dbh = DBI->connect("dbi:Oracle:$db", $dbusr, $dbpw, {RaiseError=>1, > AutoCommit=>1}) or die "Verbindung zur DB fehlgeschlagen: $DBI:: > errstr\n"; > > # Hash for variable variable names > # Hash für die verschiedenen Umgebungsgruppen > my %umg = ( > 'Auslieferungs' => 'ausl', > 'Entwicklungs' => 'entw', > 'EQS' => 'eqs', > 'IQS' => 'iqs', > 'MVB-Akademie' => 'aka', > 'Sonstige' => 'rest', ); > > while ( ( my $lang, my $kurz ) = each %umg ) { > > my $sql_$kurz = "select * from umgebungen_vw where beschreibung > like \'$lang%\'"; my $sth_$kurz = $dbh->prepare($sql_$kurz);
Instead of calling your variables $sql_$kurz and $sth_$kurz, etc. put them in %umg hash or a different one - possibly referenced by keys of a hash reference or slots of an object: {{{ my $lang_sql = $runtime_data{$lang} = NoraSqlObject->new; $lang_sql->sql( "select * from umgebungen_vw where beschreibung like \'$lang%\'" ); $lang_sql->sth($dbh->prepare($lang_sql->sql)); }}} In your case, I don't see you are using the various $kurz variables outside the loop so I don't see why you need to associate them with the varvarname. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Optimising Code for Speed - http://shlom.in/optimise <rindolf> She's a hot chick. But she smokes. <go|dfish> She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/