hi,

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:

################################# 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;
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.