in reply to Comma seperated output

while(my $line = <$log>) { $n++; $line =~ tr/\r\n//d; if ($line =~ /^(.*)INFO:.*recvd AA_BIN_MSG_GET_WLT/) { $Time_Stamp = $1; while ( $line = <$log> ) { ... while ( $line = <$log> ) {

This structure makes little sense to me. You read in a loop from $log, but then, you read in an inner loop, again from $log, and then you enter another nested loop to read until you are at the end of the file. Is this an error or do you have specific criteria why you want to read until the end of the file?

I think this is a good time to step back and make a list of what the program should actually do, and then to rewrite that code completely, as the structure and intention of this code is quite unclear to me.

Replies are listed 'Best First'.
Re^2: Comma seperated output
by namishtiwari (Acolyte) on Jun 15, 2009 at 09:52 UTC
    while(my $line = <$log>) { $n++; $line =~ tr/\r\n//d; if ($line =~ /^(.*)INFO:.*recvd AA_BIN_MSG_GET_WLT/) { $Time_Stamp = $1; while ( $line = <$log> ) { ... while ( $line = <$log> ) {
    I wanted to combine the if statements but if will only select one not all, i want the value for all the variables and then print that values in comma seperated values. This happens quite a number of time in the logfile so wanted to loop through the log file. I have to capture these data in the log file. Arcotid Time Stamp, Username, Success, Failure, Error Code, Error Message In the log snippet the userID can be found in- Code Arcot Native Server: recvd AA_BIN_MSG_VER_CHG Cert Subject String....:CN=01095848;O=MLS; UserID=012345; CardName=ARCARD Success and failure are like this- Code ArcotID Auth SUCCESS (serial Number e93b) Auth fail due to signature verification.Serial Number 11872(This is error message also) Code error code is - Authentication mechanism returned 3, here 3 is error code and for success error code is always 0. Thanks NT

      From your description, I can't see a real list of things that the program should do, in order. I interpret your sentences as the following sequence of things to be done:

      1. Read through the file line by line
      2. Whenever there is a "value"
        1. Collect that "value".

      If my interpretation is wrong, please write your own list of what the program should do. Please try to structure that list like I did, by formatting it for example with <ol><li>... tags or <code> tags, so it becomes conveniently readable.

      If my interpretation of your description matches what you want, look at your code and determine where your code does not match the description and write new code that matches the description.