|
Re: Perl and Mysql display data problem: msg#00021db.mysql.perl
Hi, Hello I have several problems. I'm trying to write a perl script that would OK, there are two main problems here, neither directly related to MySQL. While your problems are not directly MySQL related, you may have better luck (and faster responses) on one of the general Perl lists. That doesn't mean though that I'm not going to help while I can :) The first is here: my ($input_username = "bobob", $input_password = "password") You cannot assign default values in this way, you need to put the variables on one side of an '=' and the values on the other, so the line above becomes: my ($input_username,$input_password) = ("bobob", "password"); Global symbol "$input_username" requires explicit package name at ./ login.pl These two errors are related to your use of the 'strict' pragma: use strict; At the top of your script. Using this implies that all variables must be declared before use, usually with either the 'my' or 'our' keyword. In the script supplied, you've actually commented out the lines that declare these variables appropriately. Another question i have, how to write the code so it could get for example I'm not quite sure what you are asking for here; you already correctly extract the firstname and lastname into variables. To put them in a hash you might use something like: my %userdetails = ('firstname' => $fname, 'lastname' => $lname); The '=>' operator is a synonym for ',', but makes the assignment here clearer, with the hash key on the left of the operator, and the corresponding value on the right. So you could access the values using: $userdetails{'firstname'} However, since you are loading the information from a database, instead of using fetchrow_array() use fetchrow_hashref(): while (my ($row) = $sth->fetchrow_hashref()) { ... } Now you can access the fields from your query directly by name: print "Firstname: $row->{fname}, lastname: $row->{lname}\n"; Hope this helps! MC -- Martin MC Brown, Technical Writer MySQL AB, http://www.mysql.com Skype: mcmcslp -- MySQL Perl Mailing List For list archives: http://lists.mysql.com/perl To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@xxxxxxxxxxx |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Perl and Mysql display data problem: 00021, Martin J. Evans |
|---|---|
| Next by Date: | Assigning values from database to a hash or an array.: 00021, FoRo |
| Previous by Thread: | Re: Perl and Mysql display data problemi: 00021, Martin J. Evans |
| Next by Thread: | Assigning values from database to a hash or an array.: 00021, FoRo |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |