#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    421
    Rep Power
    12

    temporary tables with perl DBI


    I'm tring to make temporary tables work from a perl script. The following code is giving the error below.


    my $sql1 = qq{CREATE TEMPORARY TABLE TempTable ( id_temp int(50) NOT NULL, email_temp varchar(50) NOT NULL )};
    my $sth1 = $dbh->prepare( $sql1 );
    $sth1->execute();
    $sql2 = qq{INSERT INTO TempTable (id_temp, email_temp) values ( '$araymail->[1]', '$araymail->[3]' )};
    my $sth2 = $dbh->prepare( $sql2 );
    $sth2->execute();
    $sql3 = qq{SELECT * FROM TempTable};
    my $sth3 = $dbh->prepare( $sql3 );
    $sth3->execute();

    error


    Global symbol "$sql2" requires explicit package name at test5.pl line 203.
    Global symbol "$sql2" requires explicit package name at test5.pl line 204.
    Global symbol "$sql3" requires explicit package name at test5.pl line 206.
    Global symbol "$sql3" requires explicit package name at test5.pl line 207.
    Global symbol "$sth" requires explicit package name at test5.pl line 211.
  2. #2
  3. No Profile Picture
    Problem Solver
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2001
    Location
    Stockholm, Sweden
    Posts
    4,495
    Rep Power
    534
    Your problem is that since you are using "use strict;" perl demands that all your variables has to be declared. Which is done by using the keyword "my" and the variable name eg. these are legal:
    my $varible;
    my $variable = 0;
    my $variable = "hello";

    But if I just use a variable for the first time without having the my word in it:
    $variable = 2;

    Perl will tell you the exact errors that you got.

    One main reason to use "use strict;" is to catch spelling errors in variable names.
    eg.
    my $hello = "hello\n";
    print $helo;

    Will for instance output an empty string and a warning since the variable $helo is undefined.
    /Stefan

IMN logo majestic logo threadwatch logo seochat tools logo