Results 1 to 14 of 14

Thread: Perl Help - Are you Smart Enof

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    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

  2. #2
    scoutt
    Guest
    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?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    yea but how do i do that

    yea but how do i do that i hardly know perl

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    Help

    Please i need help with any of this one little thing would be good thanks

  5. #5
    scoutt
    Guest
    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

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    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.

  7. #7
    scoutt
    Guest
    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.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    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

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    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

  10. #10
    scoutt
    Guest
    how are you reading the file? what is in set.jas?

    and both of them links gets me a 500 server error

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    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

  12. #12
    scoutt
    Guest

    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

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    United States
    Posts
    420

    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

  14. #14
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width