well, i keep getting into some, let say basic, problems these last few days and the latest one is that i'm trying to create the same type of table in SQLite db for each my array entry. this is the exact script that is giving me trouble:
my output is only one table "tito$e". so my question is why doesn't it increment the tito0 to tito6 and creates those tables. i mean when i drop the objects and methods and create this in plain procedural way this works (the subroutines create and drop are in the same script). so if anyone could give me an insight to what happens it would be very helpful.################################# script ################################# use strict; use Table; my $table = Table->old(); my @arrayoftablenames= qw(Table1 Table2 Table3 Table4 Table5 Table6); my $e = 0; foreach (@arrayoftablenames){ $e++; my $x = qw(tito$e); $table->create(form => $stmt, name => $x); } ####################################### module ####################################### package Table; use DBI; my $dbh = DBI -> connect("dbi:SQLite:dbname=Phylll.db", "", "",{RaiseE +rror=>1, AutoCommit=>1}); sub old { ############################################### my ($class)= @_; my $hash = {}; bless ($hash,$class); } sub create{ ############################################### my ($self, %arg)=@_; my $form = $self->{form}=$arg{form}; my $tabler = $self->{name}=$arg{name}; $self->drop(argument => $tabler); my $stm = "create table $tabler ($form)"; my $st = $dbh->prepare($stm); $st ->execute(); } sub drop { ################################################# my ($self,%arg) = @_; my $arg = $self->{argument}=$arg{argument}; my $statement = "drop table if exists $arg"; my $st = $dbh->prepare($statement); $st ->execute(); } 1;
thanks
also the practical solution on how to resolve this problem using this method would be nice:)!
In reply to Autoincrement table name in the database by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |