37 users online (0 members and 37 guests)  


  Results 1 to 7 of 7

Related

  1. Replies: 4
  2. read file    Forum: CGI Perl Forum
    Replies: 0
  3. Writing to text file problem    Forum: CGI Perl Forum
    Replies: 5
  4. read and edit a file    Forum: CGI Perl Forum
    Replies: 0
  5. Email Text File    Forum: CGI Perl Forum
    Replies: 1
  1. #1
    long123's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2005
    Posts
    9

    go to read a text file evry 2 minutes

    Hi everyone!
    First I should say a big thank to all of you who helped me a lot. Now I need to trouble you one more time. I have a web page which contain 4 buttons let say A,B,C,D. the web page was created by using Perl. I have another program which was written in C++ to log down 4 types of error A,B,C,D and write it to text file called error.txt. What I want is that everytime if there is a error in text file, let say error A occur so the button A in webpage should change to red, if error B occur so the button B in webpage should change to red, dont have error C,D so these two button remain green color. Can some one help me to write a code to add into my Perl script.

    One more thing is that. I write the perl script. What it does is that there are 4 button in the page let say b1,b2,b3,b4, when button click it I want it to write to text file, if button b1 is clicked it will write to the first line, if button b2 is clicked it will write to the second line, and so on. I managed to write into a text file, but I can not write it in to line order. Can someone help me to modify my code so that I can get what I wanted. Thank you in advance. here is my code
    Code:
    #!/usr/bin/perl
    #use CGI qw(:standard); 
    
    #use CGI; 
    #$q = new CGI;
    print "Content-type:text/html\n\n";
    
    
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);
    
    open (FILE, ">try.txt") or die "an error occured: $!"; # create a new text file
    print FILE  "Error chosen: $buffer "; # write selected errors into the text file
    close (FILE); # close filehandle
    
    
    foreach $pair (@pairs) {
        ($name, $value) = split(/=/, $pair);
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        $FORM{$name} = $value;
    }
    
    print "<html><head><title>Error chosen</title></head>\n";
    print "<body>\n";
    
    print "<IMG src= mda1.jpg>";
    print "<br>";
    print "<br>";
    #print "<IMG scr =webground_lightcolors_000559.jpg>";
    print "<h2>Error Chosen</h2>\n";
    
    
    @errors = ("RFDrop","ASL","CSL","EFR");
    foreach $x (@errors) {
        if ($FORM{$x} == 1) {
    	print "Error chosen : $x.\n\n";
        }
    }
    
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    
    print "<FORM ACTION=http://localhost/~thuy/cgi-bin/errorpage.html METHOD=post ENCTYPE=multipart/form-data>";
    print "<input type=submit value=Confirm>";
    #print $q-> start_form(-method =>'POST',
    	#		-action =>"http://localhost/~thuy/cgi-bin/errorpage.html",
    	#		-target =>'');
    #print  $q->submit (-name=>'Submit button',
    #	            -value=>'Error Log' );
    print "<br>";
    print "<br>";
    print "<br>";
    print "<br>";
    print "<IMG src=tp_logo.gif>";
    print "</body></html>\n";

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: go to read a text file evry 2 minutes

    ok... i took your code, then completely redesigned it.

    i did this because i did not like the way you were doing alot of this stuff, it just made it eassier for me.

    Code:
    #!/usr/bin/perl
    #use CGI qw(:standard); 
    
    #use CGI; 
    #$q = new CGI;
    print "Content-type:text/html\n\n";
    open(ERRORFILE, "<errors.txt") || die "an error occured: $!"; # create a new text file
      @aryerrors = <ERRORFILE>;
    close(ERRORFILE);
    if(param('B1') ||  param('B2') || param('B3')){
      open(ERRORFILE, ">errors.txt") || die "an error occured: $!"; # create a new text file
      if(param('B1')){
        $aryerrors[0] = '1'; #you can put anything you want here; if you want to ad somthing use .= insted
      }elsif(param('B2')){
        $aryerrors[1] = '1'; #same thing here
      } #continue pattern if you want to add button 3 and 4 (your post said you did not need it)
      print ERRORFILE join("\n", @aryerrors);
      close(ERRORFILE);
      print "<html><head><title>Error chosen</title></head>
    <body>
    <IMG src=\"mda1.jpg\">
    <br><br>
    <h2>Error Chosen</h2>
    ";
      if(param('B1')){
        print 'Error Chosen: RFDrop';
      }elsif(param('B2'){
        print 'Error Chosen: ASL';
      }elsif(param('B3'){
        print 'Error Chosen: CSL';
      }elsif(param('B4'){
        print 'Error Chosen: EFR';
      }
    }
    print '<br><br><br><br><br><br><br><br><br>
    <FORM ACTION="http://localhost/~thuy/cgi-bin/errorpage.html" METHOD="post" ENCTYPE="multipart/form-data">
    <input type="submit" value="Confirm">
    ';
    if($aryerrors[0]){
      print '<input type="submit" value="RFDrop" name="B1" style="border: 3px solid #FF0000">';
    }elsif(!$aryerrors[0]){
      print '<input type="submit" value="RFDrop" name="B1">';
    }
    if($aryerrors[1]){
      print '<input type="submit" value="ASL" name="B1" style="border: 3px solid #FF0000">';
    }elsif(!$aryerrors[1]){
      print '<input type="submit" value="ASL" name="B1">';
    }
    #continue if you want to do the other two buttons.
    print '<input type="submit" value="CSL" name="B1"><input type="submit" value="EFR" name="B1">
    </FORM>
    <br><br><br><br>
    <IMG src=tp_logo.gif>
    </body></html>';
    1;
    i'll let you get all the bugs and stuff out of it, seen how you know enough about perl (in-other-words it is untested)

  3. #3
    long123's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2005
    Posts
    9

    Re: go to read a text file evry 2 minutes

    When I click the button. It is not written into a text file

  4. #4
    long123's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2005
    Posts
    9

    Re: go to read a text file evry 2 minutes

    Can help me the other problem first. I need it urgent. I send you the code that I have written, What I want is that, I got a web page that was created in Perl and a text file that saved 3 types of errors which are receive from my receiver. What i Want is that, when ever the RFD error is received the RFDrop button will be in red or else it will be in green, same for ASL,CSL error. Please help me to do it[CODE]#!/usr/bin/perl -w

    use CGI;
    $q = new CGI;


    print $q ->header;

    print $q ->img ({-src=>'mda1.jpg',
    -width=>'150',
    -height=>'70',
    -border=>'0'});

    print $q ->start_html (-title=>'Please select a Frequency',
    -BGCOLOR=>'#FFFFFF',
    -text=>'#339933',
    -BACKGROUND=>'webground_lightcolors_000559.jpg');

    print $q ->start_form (-method=>'POST',
    -action=>"http://localhost/~thuy/cgi-bin/servicelist.pl");

    print $q ->br;
    print $q ->font ({-size=>6,
    -color=>'#339933'}, 'Select a Frequency Band');

    print $q ->br;
    print $q ->br;
    print $q ->scrolling_list (-name=>'Choose a frequency',
    -size=>'1',
    -values=>['5A 174.928MHz', '5B 176.640MHz', '5C 178.352MHz', '5D 180.064MHz',
    '6A 181.936MHz', '6B 183.648MHz', '6C 185.360MHz', '6D 187.072MHz',
    '7A 188.928MHz', '7B 190.640MHz', '7C 192.352MHz', '7D 194.064MHz',
    '8A 195.936MHz', '8B 197.648MHz', '8C 199.360MHz', '8D 201.072MHz',
    '9A 202.928MHz', '9B 204.640MHz', '9C 206.352MHz', '9D 208.064MHz',
    '10A 209.936MHz', '10B 211.648MHz', '10C 213.360MHz', '10D 215.072MHz',
    '11A 216.928MHz', '11B 218.640MHz', '11C 220.352MHz', '11D 222.064MHz',
    '12A 223.936MHz', '12B 225.648MHz', '12C 227.360MHz', '12D 229.072MHz',
    '13A 230.784MHz', '13B 232.496MHz', '13C 234.208MHz', '13D 235.776MHz',
    '13E 237.488MHz', '13F 239.200MHz'],
    -default=>'5A 174.928MHz');
    print $q ->br;
    print $q ->br;
    print $q->submit ( -value=>'RFDrop' );
    print $q->submit ( -value=>'ASL' );
    print $q->submit ( -value=>'CSL' );
    print $q ->br;
    print $q ->br;
    print $q ->submit (-value=>'Confirm');
    print $q ->end_form, "\n";

    print $q ->br;
    print $q ->img({-src=>'tp_logo.gif',
    -width=>'150',
    -height=>'25',
    -border=>'0'});

    print $q ->end_html, "\n";

  5. #5
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: go to read a text file evry 2 minutes

    are you scrapping my code? or do you just want it done your way?

  6. #6
    long123's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2005
    Posts
    9

    Re: go to read a text file evry 2 minutes

    I spend quite long time to write those code, if possible, can you please just modify my code. if it is difficult for u that way. I dont mind that You use your own code, as long as i can get it done, it is ok. Thanks

  7. #7
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: go to read a text file evry 2 minutes

    Code:
    use CGI; 
    $q = new CGI; 
    
    
    print $q ->header; 
    
    print $q ->img ({-src=>'mda1.jpg',
    -width=>'150',
    -height=>'70',
    -border=>'0'}); 
    
    print $q ->start_html (-title=>'Please select a Frequency',
    -BGCOLOR=>'#FFFFFF',
    -text=>'#339933',
    -BACKGROUND=>'webground_lightcolors_000559.jpg'); 
    
    print $q ->start_form (-method=>'POST', 
    -action=>"http://localhost/~thuy/cgi-bin/servicelist.pl"); 
    
    print $q ->br;
    print $q ->font ({-size=>6,
    -color=>'#339933'}, 'Select a Frequency Band'); 
    
    print $q ->br; 
    print $q ->br; 
    print $q ->scrolling_list (-name=>'Choose a frequency',
    -size=>'1', 
    -values=>['5A 174.928MHz', '5B 176.640MHz', '5C 178.352MHz', '5D 180.064MHz', 
    '6A 181.936MHz', '6B 183.648MHz', '6C 185.360MHz', '6D 187.072MHz', 
    '7A 188.928MHz', '7B 190.640MHz', '7C 192.352MHz', '7D 194.064MHz', 
    '8A 195.936MHz', '8B 197.648MHz', '8C 199.360MHz', '8D 201.072MHz', 
    '9A 202.928MHz', '9B 204.640MHz', '9C 206.352MHz', '9D 208.064MHz', 
    '10A 209.936MHz', '10B 211.648MHz', '10C 213.360MHz', '10D 215.072MHz', 
    '11A 216.928MHz', '11B 218.640MHz', '11C 220.352MHz', '11D 222.064MHz', 
    '12A 223.936MHz', '12B 225.648MHz', '12C 227.360MHz', '12D 229.072MHz', 
    '13A 230.784MHz', '13B 232.496MHz', '13C 234.208MHz', '13D 235.776MHz', 
    '13E 237.488MHz', '13F 239.200MHz'], 
    -default=>'5A 174.928MHz'); 
    print $q ->br; 
    print $q ->br;
    open(ERRORFILE, "<try.txt");
    @aryerrors = <ERRORFILE>;
    close(ERRORFILE);
    #i am not sure how to do this with your way, so i am going to do it my way...
    #if there is an error have the text file with the associated line read:  style="border: 2px solid #FF0000"
    #if there is not an error have it read:  style="border: 2px solid #008000"
    #make sure it starts with a space (both of them)
    $q .= "<input type=\"RFDrop\" value=\"Submit\" name=\"RFDrop\" $aryerrors>";
    $q .= "<input type=\"ASL\" value=\"Submit\" name=\"ASL\" $aryerrors>";
    $q .= "<input type=\"CDL\" value=\"Submit\" name=\"CSL\" $aryerrors>";
    #print $q->submit ( -value=>'RFDrop' );
    #print $q->submit ( -value=>'ASL' );
    #print $q->submit ( -value=>'CSL' );
    print $q ->br; 
    print $q ->br; 
    print $q ->submit (-value=>'Confirm'); 
    print $q ->end_form, "\n"; 
    
    print $q ->br; 
    print $q ->img({-src=>'tp_logo.gif',
    -width=>'150',
    -height=>'25',
    -border=>'0'}); 
    
    print $q ->end_html, "\n";



Tags for this Thread