34 users online (1 members and 33 guests)  


  Results 1 to 4 of 4

Related

  1. Replies: 0
  2. Code Help.    Forum: Myspace Forum
    Replies: 0
  3. I need help with this code.    Forum: HTML Forum
    Replies: 1
  4. Ignore code and link greeting note code    Forum: HTML Forum
    Replies: 3
  5. need code.    Forum: HTML Forum
    Replies: 1
  1. #1
    long123's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2005
    Posts
    9

    explaining the code

    Can someone explain for me what this code does. thanks
    Code:
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);
    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;
    }

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: explaining the code

    i will explain this line by line:
    Code:
    #this line reads from the input that the script recieved into the variable "$buffer". the $ENV means "enviromental variables", so it is getting the enviromental var. 'content_length', which is the length of a file/string/exc...
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    #this line splits the string $buffer into an array (named "pairs"). the /&/ is telling it to split the file using "&" as the seperator. (example if $buffer equaled "this&that&there" it would split the array "pairs" into 3  with the outcome like this: $pairs[0]=this $pairs[1]=that $pairs[2]=there
    @pairs = split(/&/, $buffer);
    #this line is telling it to loop though this code as many times as there are arrays in $pairs. this line also tells it to temporarly use $pair for the current value of $pairs that it is on.
    foreach $pair (@pairs) {
        #this line is telling it to split $pair (the current "$pairs" array that it is on) into two variables, $name and $value,  splitting it by the "=" sign. for example: if $pair equaled "hello=goodbye", then the outcome would be: $name=hello $value=goodbye
        ($name, $value) = split(/=/, $pair);
        #this line takes out any occance of "+" in $value and replaces it with a space. (the "tr" is different than using "s" because "tr" replaces it by character, and "s" replaces the  whole thing)
        $value =~ tr/+/ /;
        #this line takes out any occurance of "a" through "f" (both higher and  lower case) and "0 though "9" with 2 values besieds eachother, with the ascii value of the caracter that it is on. the "C" is telling it with: "An unsigned char value". this line is much harder to explain, but this example may help: if $value equaled "4A" then it will change it to equal "J", which has the ascii value of 112 which in hex is "4A", did that help?
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        #this changes the value of the form (which has been submitted) with the name of the value that is stored in $name  with the translated value.
        $FORM{$name} = $value;
    #and last the eassiest line, tells it to stop the loop here.
    }
    does that answer your question?
    Last edited by ALL; 08-02-2005 at 09:50 AM.

  3. #3
    long123's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2005
    Posts
    9

    Re: explaining the code

    Thank you so much! Now I have some problems to trouble you. I am doing the project that can collect all the errors from the receiver. there are 4 errors need to be monitor which are RF DRop, ASL,CSL, EFR. What I want now is using perl script to create the web page that lets user to see how often each error occur. For example, Let say today is Monday. I will collect all errors and saved in to a textfile A.txt. I will use the data that I collected to draw a graph to see how often the error occur for example there are 2 EFR error, 4 ASL,5CSL,6RFDrop, so I can draw the graph according to that information.
    Once again, I thank for your help and hope that you can help me to solve this problem as well

  4. #4
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382

    Re: explaining the code

    are you wanting me to make it collect the errors from the same script, or is there an input for another script?

    or do you already have that part figured out, and you need me to display the errors from the file as a graph?

    do you have some code already made up?



Tags for this Thread