Home: Perl Programming Help: Beginner:
several questions



frenchface
User

May 16, 2008, 9:31 PM


Views: 11229
several questions

I have tons of questions.
1)i am making a cgi script. how do i make a text box and a search button
2)the cgi script is going to search from other .pl files to find a match (they are arrays). if i have "name 500" i want someone to search for name and the website display 500. what function would be the best to use?
3)i have a script to retrieve data from a website and manipulate it into an array. would it be better for it to print the contents into a file and have the search just look in the file. or have the .pl file opened in my cgi file and have the search search the array?
4)I want my .pl script to automatically update/run at 1am everyday. what is the best way to do that?

Thanks for everyones help. I know I am a n00b but I'm tring to learn. If you have questions about what I mean just ask me please.


KevinR
Veteran


May 18, 2008, 8:10 AM


Views: 11153
Re: [frenchface] several questions

For perl based CGI scripts look into the CGI module. To run programs automatically you use cron (unix,linux) or task (windows).
-------------------------------------------------


frenchface
User

May 18, 2008, 2:19 PM


Views: 11139
Re: [KevinR] several questions

I looked into the cgi module and all the links are broken.


KevinR
Veteran


May 19, 2008, 10:21 AM


Views: 11116
Re: [frenchface] several questions

http://perldoc.perl.org/CGI.html

If you have perl installed on your local computer the documentation is also included.
-------------------------------------------------


frenchface
User

May 20, 2008, 2:22 PM


Views: 11081
Re: [KevinR] several questions

i know that this is a perl forum but i need a simple html thing i had it working but i screwed it up.

<A href='<A href='usr/lib/cgi-bin/index.pl'>click here</A>

that is what i have but it doesnt work. it gives me a 404 error. the index.pl is located in /usr/lib/cgi-bin/


KevinR
Veteran


May 20, 2008, 3:14 PM


Views: 11072
Re: [frenchface] several questions

<A href='/cgi-bin/index.pl'>click here</A>
-------------------------------------------------


frenchface
User

May 20, 2008, 5:44 PM


Views: 11047
Re: [KevinR] several questions

ok so i have another problem. I have erro 500 internal server error. and when i look in the error log it says

[Tue May 20 20:41:39 2008] [error] (2)No such file or directory: exec of '/usr/lib/cgi-bin/index.pl' failed
[Tue May 20 20:41:39 2008] [error] [client 76.123.251.81] Premature end of script headers: index.pl, referer: http://tribalwars.engr.utk.edu/

here are my two scripts

Code
click <a href="/cgi-bin/index.pl">here</a>


and


Code
 
#!/usr/local/bin/perl
#!/usr/bin/perl
use strict;
use warnings;
use CGI ':standard';

print header,
start_html('Player Point Tracker'),
h1('Kings of War'),
start_form,
'Players Name: ',
textfield('name'), br,
submit('Search!'),
end_form, p,
hr;

print 'Your name is ', param('name'), br if param 'name';
print 'You are ', param('age'), ' years old.' if param 'age';
print end_html;



KevinR
Veteran


May 21, 2008, 12:57 AM


Views: 11023
Re: [frenchface] several questions

is the index.pl script in the cgi-bin? Are you allowed to run scripts on that sever? What is the correct shebang line?


#!/usr/local/bin/perl
#!/usr/bin/perl
-------------------------------------------------


(This post was edited by KevinR on May 21, 2008, 12:58 AM)


frenchface
User

May 21, 2008, 4:47 AM


Views: 11017
Re: [KevinR] several questions

yes the index.pl is in cgi-bin, it will work becuase i had it working then i screwed something up and i think it is
#!/usr/local/bin/perl


KevinR
Veteran


May 21, 2008, 10:02 AM


Views: 11008
Re: [frenchface] several questions

try:

#!/usr/bin/perl

or ask tech support what it should be or look in a working perl script and see what it is.
-------------------------------------------------


frenchface
User

May 21, 2008, 10:05 AM


Views: 11007
Re: [KevinR] several questions

i dont think the problem is the script, because i'm getting a 404 error meaning page not found, i think if it is something with the script it would be a 500 error


KevinR
Veteran


May 21, 2008, 10:18 AM


Views: 11006
Re: [frenchface] several questions

try the full url for now:


Code
click <a href="http://www.yoursite.com/cgi-bin/index.pl">here</a>

-------------------------------------------------


frenchface
User

May 21, 2008, 1:32 PM


Views: 11001
Re: [KevinR] several questions

ok i got that working, no i have another question i have the index.pl

Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI ':standard';

print header,
start_html('Player Point Tracker'),
h1('Kings of War'),
start_form,
'Players Name: ',
textfield('name'), br,
submit('Search!'),
end_form, p,
hr;
$query->import('e.pl');
print 'Your name is ', param('name'), br if param 'name';
print end_html;


and i want it to import serval perl scripts and be able to searh the arrays of the scripts, i think i use the import() is that right and what command do i use to have it search the array? the scipts look like this


Code
my $url = 'http://en19.tribalwars.net/map/tribe.txt'; 
use LWP::Simple;

my $content = get $url;
@array=split(/,/, $content);
$n=1;
$j=4;
do
{
print "@array[$n] @array[$j]\n";
$n=$n+5;
$j=$j+5;
}
while ($n<=$#array);


In Reply To


KevinR
Veteran


May 21, 2008, 2:52 PM


Views: 10997
Re: [frenchface] several questions

is there a good reason the use a seperate perl script? Make life easier if you just combine it all in one script.
-------------------------------------------------


frenchface
User

May 21, 2008, 2:55 PM


Views: 10996
Re: [KevinR] several questions

this is for a game and what i am tring to do is to see what times a player is online and when they are not so want i want to do is have 12 scripts that update daily each one at a different hour, so 1 updates at midnight, then another one at 2. etc, do you know how to up that all in 1 script.


frenchface
User

May 21, 2008, 4:23 PM


Views: 10988
Re: [frenchface] several questions

some reason i edit my cig script it doesnt work so i change it back and i got a 500 server error is there something wrong with my script?


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI ':standard';

print header,
start_html('Player Point Tracker'),
h1('Kings of War'),
start_form,
'Players Name: ',
textfield('name'), br,
submit('Search!'),
end_form, p,
hr;

print 'Your name is ', param('name'), br if param 'name';

print end_html;



KevinR
Veteran


May 21, 2008, 7:51 PM


Views: 10978
Re: [frenchface] several questions

looks OK, make sure you uplaod the file in ASCII (text) mode if using an FTP client to transfer from your PC to a server.
-------------------------------------------------


frenchface
User

May 21, 2008, 9:02 PM


Views: 10973
Re: [KevinR] several questions

hmmm, thats what it is on the server, i'm using putty and pico.


KevinR
Veteran


May 22, 2008, 12:24 AM


Views: 10968
Re: [frenchface] several questions

look in the sever error logs.
-------------------------------------------------


frenchface
User

May 22, 2008, 1:23 PM


Views: 10931
Re: [KevinR] several questions

i dont understand why i am getting the first one becuase the index.pl is not located there it is in var/www/cgi-bin/


[Thu May 22 15:39:19 2008] [error] (13)Permission denied: exec of '/usr/lib/cgi-bin/index.pl' failed
[Thu May 22 15:39:19 2008] [error] [client 160.36.235.98] Premature end of script headers: index.pl, referer: http://tribalwars.engr.utk.edu/


KevinR
Veteran


May 22, 2008, 2:20 PM


Views: 10928
Re: [frenchface] several questions

Does the script have execution bits turned on? chmod 755.
-------------------------------------------------


frenchface
User

May 22, 2008, 2:24 PM


Views: 10927
Re: [KevinR] several questions

yes it has the correct permissions


KevinR
Veteran


May 22, 2008, 3:31 PM


Views: 10923
Re: [frenchface] several questions

I don't know, ask your tech support guys.
-------------------------------------------------


frenchface
User

May 22, 2008, 4:02 PM


Views: 10917
Re: [KevinR] several questions

ok i figured it out, some reason it was looking in a different cgi-bin, so back to my questions

ok i got that working, no i have another question i have the index.pl
Code

#!/usr/bin/perl

use strict;
use warnings;
use CGI ':standard';

print header,
start_html('Player Point Tracker'),
h1('Kings of War'),
start_form,
'Players Name: ',
textfield('name'), br,
submit('Search!'),
end_form, p,
hr;
$query->import('e.pl');
print 'Your name is ', param('name'), br if param 'name';
print end_html;


and i want it to import serval perl scripts and be able to searh the arrays of the scripts, i think i use the import() is that right and what command do i use to have it search the array? the scipts look like this

Code

my $url = 'http://en19.tribalwars.net/map/tribe.txt';
use LWP::Simple;

my $content = get $url;
@array=split(/,/, $content);
$n=1;
$j=4;
do
{
print "@array[$n] @array[$j]\n";
$n=$n+5;
$j=$j+5;
}
while ($n<=$#array);


frenchface
User

May 22, 2008, 6:32 PM


Views: 10910
Post deleted by frenchface

 


frenchface
User

May 22, 2008, 7:20 PM


Views: 2703
Re: [frenchface] several questions

ok, so i can import the data, however it prints it all on the page


use strict;
use warnings;
use CGI ':standard';

print header,
start_html('Player Point Tracker'),
h1('Kings of War'),
start_form,
'Players Name: ',
textfield('name'), br,
submit('Search!'),
end_form, p,
hr;

print 'Your name is ', param('name'), br if param 'name';
$a=eval { require "e.pl"};
$b=grep(/param('name')/,$a);
print ' $b';


frenchface
User

May 22, 2008, 7:40 PM


Views: 2701
Re: [frenchface] several questions

could i have the perl script output all the values in maybe a .txt file, then have the cgi open it and search in it?


frenchface
User

May 24, 2008, 8:56 PM


Views: 2661
Re: [frenchface] several questions

i got it working