|
-
Mar 5th, 2002, 05:45 PM
#1
Thread Starter
Hyperactive Member
Perl Help - Are you Smart Enof
Ok i need yto know a couple thing help on any would be fine
ok ya see now i have a vb app that will contact my site like this
(quick question does it matter what extention i have for it to work)
/go.jas&IpAdress&VersionNumber&UserName
now hat i need is sript to split that appart and save stuff to a text file with extention .jas and the name get so get.jas and store the data as following
ip(jm)username(jm)Version(jam)ip(jm)username(jm)Version
have jm separate from one users info and use jam to seperat differnt users.
Making sure that there is no jam at the end
any help on any one of these things would be very much appreshated if you help i could offer some good programs in vb to ya
-
Mar 5th, 2002, 06:08 PM
#2
the only thing I can see that might be a problem is that your server will not recognise that extension, but easily fixed if you have root access to your server.
also you might find that it will be easier to make them variables.
/go.jas?Ip=jm&VersionNumber=jm&UserName=whatever
that way perl can just see that Ip=jm.
see what I am saying?
-
Mar 5th, 2002, 06:54 PM
#3
Thread Starter
Hyperactive Member
yea but how do i do that
yea but how do i do that i hardly know perl
-
Mar 6th, 2002, 10:51 AM
#4
Thread Starter
Hyperactive Member
Help
Please i need help with any of this one little thing would be good thanks
-
Mar 6th, 2002, 11:08 AM
#5
first you have to set the .jas extension to be parsed in CGI. until that is done I can't help you. unless you make the .jas extension to a .cgi or .pl
-
Mar 6th, 2002, 04:34 PM
#6
Thread Starter
Hyperactive Member
ok i can change it
can you help now. if you can do it i am willing to pay you for it. anyone if you can do what i am asking i can pay ya for it. i can pay you money or i can give you visual studio 6 wicth ever you would like.
-
Mar 7th, 2002, 01:13 PM
#7
ok try this.
save it as whatever.jas and then run it.
Code:
#!usr/bin/perl
$Datafile = "data.txt";
$qs = $ENV{'QUERY_STRING'};
open(THEFILE,">>$Datafile") || die "Can't open $Datafile: !$\n";
flock(THEFILE, 2); #Lock
@str = split(/&/, $qs);
print THEFILE "ip=$str[0]|VersionNumber=$str[1]|Username=$str[2]\n";
flock(THEFILE, 8); #Free
close(THEFILE);
I used | instead of (jm) and it will be printed on a seperate line each time so it will be easier to read in the future.
let me know if it works as it is untested.
-
Mar 7th, 2002, 05:51 PM
#8
Thread Starter
Hyperactive Member
works greats thanks so much
works greats thanks so much. and i dont meen to be a peser but is there a way that i could possible clear this text file like every 5 minets or so. it would be great to do if not thats fine. but once againg thanks it works great
-
Mar 7th, 2002, 06:18 PM
#9
Thread Starter
Hyperactive Member
ut o
i am having probles it writes to the text file set.txt but then when i got to read it throught http it give me a server 500 error. and does not alow me to read it but when i view it throuhgt ftp it works fine
(this like give me server 500 error but it still works so i am not worried)
http://leotown.netfirms.com/cgi-bin/...?mo&jo&working
(this lik does not i can see it in ftp but not in http)
http://leotown.netfirms.com/cgi-bin/get.jas
-
Mar 7th, 2002, 08:28 PM
#10
how are you reading the file? what is in set.jas?
and both of them links gets me a 500 server error
-
Mar 8th, 2002, 10:56 AM
#11
Thread Starter
Hyperactive Member
i know
the first link works it justs give me an error buti cannot read the second file i can only read it in ftp
-
Mar 8th, 2002, 11:02 AM
#12
Re: ut o
Originally posted by isurftheweb
i am having probles it writes to the text file set.txt but then when i got to read it throught http it give me a server 500 error. and does not alow me to read it but when i view it throuhgt ftp it works fine
that is what I asked. how are you reading the file in http? going like this
http://leotown.netfirms.com/cgi-bin/set.txt
-
Mar 11th, 2002, 10:59 AM
#13
Thread Starter
Hyperactive Member
ok i got it
ok i got it now i wne tna dlerned perl and i made just hwta i need what i did was made 3 cgi files one called get.jas the other called set.jas and the other called tim.jas the first one set.jas what it does is it stores to a file called data.txt and then what it does is each time it add a person it puts a && between each persons info. it check to see if the file is empty and if it is it does not put && infront of it so an example would be. then when it gets done it outputs good to let me know every thing is ok
127.0.0.1&15&jason&&127.0.0.2&15&jessica
the code for this file is
Code:
#!perl
$file = "data.txt";
$oldti = "oldtime.txt";
$Minute = (localtime)[1];
$Hour = (localtime)[2];
$min = "min.txt";
open (filea, "< $min") or die "can't open file for output";
$minet = <filea>;
close filea;
open (filea, "< $oldti") or die "can't open file for output";
$old = <filea>;
close filea;
if ($Minute + $Hour * 60 > $old + $minet) {
open(CF,">$file");
print CF "";
close(CF);
open(CF,">$oldti");
print CF $Minute + $Hour * 60;
close(CF);
}
if ($Minute + $Hour * 60 < $old) {
open(CF,">$file");
print CF "";
close(CF);
open(CF,">$oldti");
print CF $Minute + $Hour * 60;
close(CF);
}
$spl = "&";
$str = $ENV{'QUERY_STRING'};
@ara = split(/&/, $str);
if (@ara eq 4) {
shift(@ara);
}
$ths = join($spl,@ara);
open (filea, "< $file") or die "can't open file for output";
$old = <filea>;
close filea;
$nuse = 0;
@arb = split(/$spl$spl/, $old);
foreach $a (@arb) {
@arc = split(/$spl/, $a);
foreach $b (@arc) {
if ($ara[0] eq @arc[0]) {
$nuse = 1;
}}}
if ($nuse eq 0) {
$code = "$old$spl$spl$ths";
if ($old eq "") {
$code = "$ths";
}
open(CF,">$file");
print CF $code;
close(CF);
}
print "Content-Type: text/html\n\n";
print "good";
the code also check to see if it has been 5 mintes from the last time the code was accesed and if it was then it deletes all the info in the data.txt . then with get.jas what it does is it replaces the & with (jm) and replaces the && with (ja) and replaces %20 with a space then despays the data. this file also check to see if it has been 5 minets since last view
the code for get.jas is
Code:
#!perl
$file = "data.txt";
$file = "data.txt";
$oldti = "oldtime.txt";
$Minute = (localtime)[1];
$Hour = (localtime)[2];
$min = "min.txt";
open (filea, "< $min") or die "can't open file for output";
$minet = <filea>;
close filea;
open (filea, "< $oldti") or die "can't open file for output";
$old = <filea>;
close filea;
if ($Minute + $Hour * 60 > $old + $minet) {
open(CF,">$file");
print CF "";
close(CF);
open(CF,">$oldti");
print CF $Minute + $Hour * 60;
close(CF);
}
if ($Minute + $Hour * 60 < $old) {
open(CF,">$file");
print CF "";
close(CF);
open(CF,">$oldti");
print CF $Minute + $Hour * 60;
close(CF);
}
print "Content-Type: text/html\n\n";
open (filea, "< $file") or die "can't open file for output";
$data = <filea>;
close filea;
@data = split(/&&/,$data);
$data = join("(jam)",@data);
@data = split(/&/,$data);
$data = join("(jm)",@data);
@data = split("%20",$data);
$data = join(" ",@data);
if ($data eq "") {
$data = "No(jm)Users(jm)On"
}
print $data;
and last of all the tim.jas just sets how many minets apart to delete the data.txt. thats to your website likes i lerned how to do all this i looked at perl 101 and lerned so much from it thats againg for all your help
-
Mar 11th, 2002, 11:45 AM
#14
cool, I'm glad you have it working. and that's what my site is for, to help out people that are just learning, plus the more advanced programmers.
thank you for stopping by.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|