By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,426 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

Unable to print out intended text - just prints out the contents of .pl file.

Markus
Expert 5K+
P: 6,050
I'll leave out the annoying 'i'm a newbie' speech and get to the point: i'm a newbie at perl ;)

First thing i ever wrote in perl and it doesnt work.

I'm using xampp as my localhost - with perl installed on that. When i run this (http://localhost/mysql.pl) it just prints out the contents of the file and not an array if the databases...

Enlighten me, oh gods of perl
Expand|Select|Wrap|Line Numbers
  1. #!"C:\xampp\perl\bin\perl.exe"
  2.  
  3. # PERL MODULE WE WILL BE USING
  4. use Mysql;
  5.  
  6. # HTTP HEADER
  7. print "Content-type: text/html \n\n";
  8.  
  9. # MySQL CONFIG VARIABLES
  10. $host = "localhost";
  11. $database = "...";
  12. $tablename = "...";
  13. $user = "...";
  14. $pw = "...";
  15.  
  16. # PERL MYSQL CONNECT
  17. $connect = Mysql->connect($host, $database, $user, $pw);
  18.  
  19. # LISTDBS()
  20. @databases = $connect->listdbs;
  21. foreach $database (@databases) {
  22.     print "$database<br />";
  23. }
  24.  
Jan 6 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
I'll leave out the annoying 'i'm a newbie' speech and get to the point: i'm a newbie at perl ;)

First thing i ever wrote in perl and it doesnt work.

I'm using xampp as my localhost - with perl installed on that. When i run this (http://localhost/mysql.pl) it just prints out the contents of the file and not an array if the databases...

Enlighten me, oh gods of perl
Expand|Select|Wrap|Line Numbers
  1. #!"C:\xampp\perl\bin\perl.exe"
  2.  
  3. # PERL MODULE WE WILL BE USING
  4. use Mysql;
  5.  
  6. # HTTP HEADER
  7. print "Content-type: text/html \n\n";
  8.  
  9. # MySQL CONFIG VARIABLES
  10. $host = "localhost";
  11. $database = "...";
  12. $tablename = "...";
  13. $user = "...";
  14. $pw = "...";
  15.  
  16. # PERL MYSQL CONNECT
  17. $connect = Mysql->connect($host, $database, $user, $pw);
  18.  
  19. # LISTDBS()
  20. @databases = $connect->listdbs;
  21. foreach $database (@databases) {
  22.     print "$database<br />";
  23. }
  24.  
If it is printing the contents of the Perl file, instead of executing it, then either the web sever you are using is setup to ONLY execute .cgi files, or not setup to serve CGI at all. You need to figure that out.

Regards,

Jeff
Jan 7 '08 #2

Markus
Expert 5K+
P: 6,050
Ahh, thought so. -_-

danke
Jan 7 '08 #3

eWish
Expert 100+
P: 971
Since you are a complete newbie, now is the time to learn good coding practices :).

CGI.pm
Declare your variables
Pragmas strict & warnings

Also bookmark perldoc.perl.org

--Kevin
Jan 7 '08 #4

Markus
Expert 5K+
P: 6,050
Since you are a complete newbie, now is the time to learn good coding practices :).

CGI.pm
Declare your variables
Pragmas strict & warnings

Also bookmark perldoc.perl.org

--Kevin
I'm on it!

Just as soon as i can get this xampp / perl thing sorted _
Jan 7 '08 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
I'm on it!

Just as soon as i can get this xampp / perl thing sorted _
Ok, first, from the xampp page, here is the link that shows where the configuration files are located. You will specifically need the one for apache.

Once you have that, then you can follow the apache configuration for configuring cgi.

Personally though, I would first try changing the extension of my perl script to ".cgi" instead of ".pl" and see if it is already configured for that.

Regards,

Jeff
Jan 7 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.