16 Replies Latest reply on Feb 25, 2009 7:04 PM by

    loop process

      i need to split the log into several categories..
      but my coding only works at the first sentences of the log..
      this is the example of log that need to be splitted.. - - [31/Oct/2008:02:24:21 +0800] "GET /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1" 200 14400 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; + http://www.google.com/bot.html)" - - [31/Oct/2008:02:27:27 +0800] "GET /bppk_en/login/login.php HTTP/1.1" 200 - - [31/Oct/2008:02:36:01 +0800] "GET /TMimages/line.gif HTTP/1.1" 200

      my problem is the code that made by me only splitted at the ip no
      how to make it also works at the ip no and so on..

      this is the code made by me-->
        • 1. Re: loop process
          anyone can help me?
          • 2. Re: loop process
            ntsiii Level 3
            Is the split on "\n" working correctly?
            1 person found this helpful
            • 3. Re: loop process
              yes. it does not occur any error..
              i just found out that without this code-->

              for each(var line:String in myText.text.split("\n")

              the log still can splitted into those categories..
              so, i already delete for..each code into my coding
              my question is how to make the splitting process also occur at the next sentences?
              and this is my code..
              • 4. Re: loop process
                ntsiii Level 3
                I asked if it was working correctly, not if it was erroring.

                Is it placing each line of text in an element of the array?

                It looks like your lines might be separated by two newline chars, not one.
                • 5. Re: loop process
                  thank you for reply.
                  yes. it is placing each line of text in the element of array.
                  i do not think that mylines is separated by twonew lines characters..
                  if so, i already try it but still not working..
                  • 6. Re: loop process
                    i think you should be expert on this. can you give me the example of how should be the coding?
                    • 7. Re: loop process
                      flexstone Level 1
                      Using regExp to split maybe better so that you cover both possibilities that the newline is either "\r" or "\n"



                      note that without the "g" (global) parameter the split will act on the first occurrence only....
                      • 8. Re: loop process
                        Level 7
                        I'm actually surprised that you aren't getting the last line as your
                        final value. You're setting all the values to the same instance of the
                        same object. Since you aren't making a copy of it before putting it in
                        the array, you're just filling the array with a bunch of copies of the
                        same thing.

                        Can you set a breakpoint in your loop and see if it's executing more
                        than once, and what the value of line is each time?
                        1 person found this helpful
                        • 9. Re: loop process
                          thank guys for reply.
                          it helps..
                          hi Nate!
                          i'm new in flex and also in programming..
                          i try to add for..each statement based on your request but it is come out the bunch of the same copies of the same thing..
                          this the code for..each statement that was inserted by me--->

                          for each(var line:String in myText.text.split(" \n"))
                          for each(var word:String in line.split(" ")

                          and i think it has the problem with bold thing.
                          do you have some ideas and please give me some example to make me understand..
                          • 10. Re: loop process
                            this is my coding in the section of this function
                            • 11. Re: loop process
                              Level 7
                              I'm pretty sure you're getting further away from what you want to do.
                              Try this:

                              private function applicationCompleteHandler():void {
                              var stringToSplit:String = myText.text;
                              var result:Array = new Array();

                              for each(var line:String in myText.text.split("\n")) {
                              var Split:LogReader = new LogReader();
                              Split.ip = result[0];
                              Split.date = result[3] + result[4];
                              Split.method = result[5];
                              Split.info = result[6] + result[7];
                              Split.status = result[8];

                              I kind of doubt that this will work, since I don't really know what
                              you're trying to do, or what your variables mean. Hopefully, though,
                              you'll be able to get some idea of what a loop is.

                              You should look up the following: "iteration", "object oriented
                              programming", and "debugging". Try googling each of them, with and
                              without "Flex 3". All of these are necessary concepts if you want to
                              program in Flex.

                              If you're using Flex Builder, run a debug build. The code I'm posting
                              should print out text to the console. If you have any more problems,
                              please post that text. If you aren't using Flex Builder, then add "fdb"
                              to the list of things you need to look up.
                              1 person found this helpful
                              • 12. Re: loop process
                                thanks Nate..
                                but its still not working..
                                actually i'm trying to do the system after the logfile uploaded to the system it can be splitted into several categories after click the button..
                                this is the example of logfile

                       - - [31/Oct/2008:02:24:21 +0800] "GET /bppklms/index.php?cal_m=2&cal_y=1995 HTTP/1.1" 200 14400 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; + http://www.google.com/bot.html)"

                       - - [31/Oct/2008:02:27:27 +0800] "GET /bppk_en/login/login.php HTTP/1.1" 200 3736 " http://www.bppk.gov.my/login/login.php?msj=You%20Have%20Been%20Forced%20to%20Logout" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729)"

                       - - [31/Oct/2008:02:36:01 +0800] "GET /TMimages/line.gif HTTP/1.1" 200 63 " http://bppk.gov.my/" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/2008092417 Firefox/3.0.3"

                                the sentence splitted based on the sign space (" ") between each word. and it works!
                                but it only works at the first sentences..
                                i'm trying to do lot of things to make it also works the next sentences and so on.. but i still stuck.
                                i hope u can understand what's the system is.
                                here, i attach the whole code and i really hope what is the error or something that make my system does not work properly
                                • 13. Re: loop process
                                  what's wrong with my codes??
                                  • 14. Re: loop process
                                    i got some warning here when i execute the code.
                                    it says---> 1008: variable 'line' has no type declaration.

                                    what should i do?
                                    is it make my code does not work properly?
                                    how to solve this??

                                    hope Nate, Greg, flexstone or others still interested discussing this.
                                    • 15. Re: loop process
                                      Level 7
                                      There are a lot of things wrong with your code, many of which have
                                      already been pointed out. I don't have time to write your program for
                                      you, and I don't think anyone else will either.

                                      I gave you a number of things to Google, and I suggest that you do so,
                                      and read as many flex docs as you can. In addition, if you haven't gone
                                      through Flex in a Week, I suggest you do that as well.
                                      • 16. Re: loop process
                                        but i dont have so much time to learn everything to make my code correct.
                                        it is my assignment.
                                        but of course later i will learn flex more harder bcause its interesting than others.
                                        any way, thank you Nate!