perl - Error-global symbol requires explicit package name -
i trying print values of database table on webpage in table format.i using perl file having .cgi extension.whenever try run code error "global symbol requires explicit package name".the rows of database table should displayed onload it's not happening..
i have tried lot can't understand whats wrong code..
please help..
code of people.cgi file ..
#!/usr/bin/perl use cgi; use dbi; use strict; use warnings; print "content-type:text/html\r\n\r\n"; #$q = cgi->new; #print $q->header; $dsn = "dbi:mysql:demo:localhost"; # data source name $username = "mint"; # user name $password = "mint123"; # password $dbh; $sth; # database , statement handles $dbh = dbi->connect($dsn, $username, $password); $sth = $dbh->prepare("select * people"); $sth->execute(); print "<h1>ganesh</h1>"; print "<table > <tr> <th>id</th> <th>name of people involved</th> <th>position</th> <th>roles(a user can have multiple roles)</th> <th>notes</th> </tr>"; while( $href = $sth->fetchrow_hashref ) { print "<tr>"; print "<td>$$href{'id'}</td>"; print "<td>$$href{'name'}</td>"; print "<td>$$href{'pos'}</td>"; print "<td>$$href{'role'} </td>"; print "<td>$$href{'notes'}</td>"; #print "<td><input type='text' value=\"$$href{'display_name'}\" id =\"dis-$$href{'windows_id'}\" readonly> </td>"; #print "<td><input type='text' value=\"$$href{'email_id'}\" readonly> </td>"; print "</tr>"; } print "</table>"; $sth->finish(); $dbh->disconnect();
error messages..
global symbol "$href" requires explicit package name @ people.cgi line 31. global symbol "$href" requires explicit package name @ people.cgi line 34. global symbol "$href" requires explicit package name @ people.cgi line 35. global symbol "$href" requires explicit package name @ people.cgi line 36. global symbol "$href" requires explicit package name @ people.cgi line 37. global symbol "$href" requires explicit package name @ people.cgi line 38. execution of people.cgi aborted due compilation errors.
the structure of mysql table..it has 14 coloumns...it has no data inside it...
$href
should defined (usually my
local/lexical variables) puts it's scope inside while loop in particular case.
while (my $href = $sth->fetchrow_hashref ) { .. }
Comments
Post a Comment