go ahead... be a heretic | |
PerlMonks |
Reading a MySQL table into an arrayby davies (Prior) |
on Jul 30, 2005 at 11:22 UTC ( [id://479596]=perlquestion: print w/replies, xml ) | Need Help?? |
davies has asked for the wisdom of the Perl Monks concerning the following question:
Dearly beloved brethren, In my personal pilgrimage to enlightenment, I am trying to convert a VB6 programme to Perl. This programme reads Excel files, writes them to MySQL, hacks the database around and produces more Excel files. Because Excel and VB6 use different connections to MySQL, I cannot make the final output tables (that are to be passed from MySQL to Excel) temporary files, because the Excel connection would be unable to see them. However, MessWare crashes far more often than I like. When it does this, it may leave tables on the database that are no use to monk or beast. I therefore want some code available that reads all the database tables, compares them to a list, and deletes them if they are not in the list. Now, I know how to read data from a MySQL table and put it into a Tk listbox. This was taken from one of the man pages or docs, and works perfectly in a variety of situations. My plan, therefore, was thus: 1) Create a table listing the tables that should exist (including itself!). 2) Read the list of tables that actually exist into an array. 3) Run through the array, comparing each table to the table of table names, deleting the table if it isn’t in the table of tables. (1) is easy and complete. But (2) has got me stumped. I get either one table name only, or the right number of tables, but all called 1. I have created a module called SQL, which gets called from any number of other modules. Strict, warnings and diagnostics are in every file. The relevant parts of the SQL module are: The following code produces just the last table name: This produces a list of "1" I find it hard to believe that this is a complex problem, but it’s doing my hubris no good to realise that it’s too complex for me. I don’t know if it’s connected, but I’d be extra grateful if some kind soul would clear up my incomprehension on @ary. Mummy always told me that a Perl variable starting with @ was an array. However, in the code I have that populates listboxes correctly, @ary seems to work as a scalar. This code appears within the SQL module: I have tried several solutions involving $ary[$i] and similar constructs, but without useful results. This isn’t urgent, except that the brick walls of my hermitage are starting to show damage from me beating my head against them. TIA and, as Dave Allen used to say, “may your God go with you”. John Davies Update: My system configuration
Back to
Seekers of Perl Wisdom
|
|