running cgi files

Status
Not open for further replies.

reydim

New Member
Messages
5
Reaction score
0
Points
0
Hi, this my first time here. I'm studying perl and i'm just wondering how i can run cgi files from my panel.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
ok, first make sure that your path to perl is correct:
Code:
#!usr/bin/perl

Also i advise using strict and maybe even diagnose to save urself time with undefiened variables.

the connect to your site via ftp and open /public_http/cgi-bin/ and put your scripts in there.

If you want to see what modules are installed on the server:

http://www.defectalisman.exofire.net/cgi-bin/tools/check_mod.pl

My page is a working example of perl.

http://www.defectalisman.exofire.net/

Good luck man.
Edit:
Oh, sorry forgot to give you the cookie link:

http://www.defectalisman.exofire.net/cgi-bin/tools/cookie.pl?mngr1 is for a mod.

The page is basic as I have now abandoned the idea of creating a CMS with perl and moved on to using php. It is so similar yet so different. Easier as it can be written in the html document.
Edit:
Would be intrested to see what you some up with so let me know!
 
Last edited:

reydim

New Member
Messages
5
Reaction score
0
Points
0
Thanks for your reply.
I created this file test.cgi (code below) and store it in /public_html/cgi-bin

#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

print "Hello, PERL!";

Then, try to access it using http://<my domain>.x10hosting.com/cgi-bin/test.cgi but i got message "Explorer cannot display the web page".

How can i view the cgi file that i created?
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
After uploading it you have to set the rights to the script.

If you are using a ftp program then just right click the uploaded script and set permissions to 755.

If not, is that all thats in the script?
Edit:
If i may ask where and why are you studying Perl?
Edit:
use CGI::Carp qw(fatalsToBrowser);

Whats the point in that?

There is no die in the script, so no special error message would be printed.

Better to create a error sub and use "or" to you sub with the message. You can now log the message and print it to the browser through a template.
 
Last edited:

reydim

New Member
Messages
5
Reaction score
0
Points
0
I set permission to 755 and still doesn't work. Is the location of the file correct? Also, did i get the right url to access test.cgi? Sorry, i'm really a newbie in Perl and i want to learn it for job related purposes. The codes i just copied it from tutorial lesson online and put in test.cgi.

I really want to see the output. Thanks.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
ah... this sever reads perl as *.pl
Edit:
sorry, should have seen that.
Edit:
If your script was pure perl it might run as a *.cgi file. This mainly would consist of using no modules like cgi.
eg:
Code:
#!/usr/bin/perl
$text = 'hello world';
print "$text\n";

If i can offer any advice it would be this.

The ActivePerl user guide is the best bet for learning purposes. It doesn't just follow one methode or style of programing in its examples, but many and all.
If you have ActivestatePerl installed : %root%/html/index.html

Also as I said earlier, "use STRICT;" when programing locally. As your program grows and you forget to define variables you will notice the need for it.

I preffer the perlish approach, rather than php's way of scripting. But perl can only be stored on the server and run on the server. php can be written in to *.html files and *.php, but still only runs on the server.

You can pm me if you need any further help. I am not a pro, but am willing to help if i can.
 
Last edited:

reydim

New Member
Messages
5
Reaction score
0
Points
0
At last, it works now! Thanks a lot. Ok i will check ActivePerl and see what i can learn from this.

Can u give me an example of "use STRICT", it's seems very handy coz' you really recommend to use it. Right i'm using online tutorial from Tizag.
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Code:
#!usr/bin/perl

[B]use strict;[/B]
[B]use diagnostics;[/B]
use CGI;
use tk;

sub doing_it {
$var = "10";
}

print "$var\n"; 
# this will print an error if strict is enabled.  Reason it has fallen out of scope.  Localy without strict it wont print the error.  It might print the "10\n" or not.

Code:
#!usr/bin/perl

[B]use strict;[/B]
[B]use diagnostics;[/B]
use CGI;
use tk;

my($var);

sub doing_it {
$var = "10";
}

print "$var\n"; 
# this is now a global and will work as expected.
Edit:
Sorry just another thing.

If the scalar/array/hash is not needed through out the script then define it in the scope it is needed.

eg:
Code:
...

sub doing_it {
my $var = "10";
print $var + 10."\n"; # Will work as expected
}

print $var; # out of scope again

I tend to assign a $tmp, @tmp, %tmp, as globals and use these through out where i need something to be stored temporarily. When it is used and no longer needed just $tmp = undef or $tmp = "";

The $ENV vars are very usfull to ($_, @_);

If a variable is only needed in say 2 subs and no where lese in the script you could define as a global and use that little bit of ram or you could define it in the 1st case it is needed and then pass it to the next sub.

eg:

Code:
...

sub doing_it {
  my $var = "10";
  &go_for_it($var)
}

sub go_for_it {
 my ($tmp) = @_;
print "$tmp\n"; # would print "10"
}

print "$tmp\n"; 
print "$var\n"; # both of these are out of scope unless you had defined either as a global, then witht the above code you will get an error with strict on saying something like "earlier decleration of global variable"
 
Last edited:
Status
Not open for further replies.
Top