AutoHotkey Community

It is currently May 25th, 2012, 9:45 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: November 26th, 2007, 3:22 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Hi,

I've read a file into a variable (CurrentFile), and am using a parsing loop to process each line of the file. As part of the processing, I want to append the next line from CurrentFile to the current line, without using Continue to jump back to the top of the parsing loop.
Code:
Loop, parse, CurrentFile, `n
{
  step 1
  step 2
  ...
  step n
    append the next line in CurrentFile to the current line (Line`nNextLine)
    process the combined lines
  step n+1
  ...
}

I want the next iteration of the parsing loop to start on the line after the one I appended.

I haven't found any way to get the current position of the parsing loop, so I don't know how to tell it to get the next line and append it to the current line. Is there an easy way to do this inside a parsing loop?

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 4:03 pm 
Offline

Joined: February 9th, 2006, 8:36 pm
Posts: 338
maybe
Code:
bJoin=
loop, parse, CurrentFile,`r,`n
{
   IfNotEqual,bJoin,
   {   bJoin=
      CurLine=%CurLine%`n%A_LoopField%
   }
   ;.........
   if (NeedToJoin)
   {   bJoin=1
      CurLine=%A_LoopField%
      continue
   }
   ;Process CurLine instead of A_LoopField
   ;........
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 4:21 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Hi wOxxOm,

That's what I originally considered, but it has to be done without using "Continue".

Is there any way to access and increment the index/pointer in a parsing loop? If not, then maybe reading the lines into an AHK pseudo-array is the answer?

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 4:29 pm 
Offline

Joined: February 9th, 2006, 8:36 pm
Posts: 338
no, there isn't. What's wrong with continue?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 4:40 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
x0xx0m wrote:
Quote:
no, there isn't. What's wrong with continue?


The test for needing to append the next line comes in the middle of the processing (as shown in the original post).

1. After appending the next line, I want to keep processing the combined line down to the end of the loop. There are a number of steps after the append.

2. I don't want to process the combined line with the part of the loop above the text step where I append the next line. If I use a continue, the processing jumps back to the beginning of the loop.

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 4:56 pm 
Offline

Joined: February 9th, 2006, 8:36 pm
Posts: 338
just add 'else' part with parentheses
Code:
bJoin=
loop, parse, CurrentFile,`r,`n
{
   IfNotEqual,bJoin,
   {   bJoin=
      CurLine=%CurLine%`n%A_LoopField%
   }
   else
   {
      ;.........
      if (NeedToJoin)
      {   bJoin=1
         CurLine=%A_LoopField%
         continue
      }
   }
   ;Process CurLine instead of A_LoopField
   ;........
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 5:16 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
So it would look like this?

Code:
bjoin = false
Loop, parse, CurrentFile, `n
{
  If bjoin = false
  {
    step 1
    step 2
    ...
    step n     ; test for need to join
    If need to join
    {
      bJoin=true
      CurLine=%A_LoopField%
      continue
     }
  }
    step n+1
    ...
    bjoin = false
}


I think this would work if I had only one instance of needing to join lines, but there are multiple instances, and in each case, I'd have to add another if condition for bjoin1, bjoin2, bjoin3, bjoin4.... It rapidly gets unmanageable. So again, I'm looking for a method that doesn't use "continue".

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 9:27 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
just a thought, but have you considered using [StringSplit] on your input file and having a normal [loop] iterate through the array elements ?

With that method, you'd have more control over which element gets accessed next.

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 9:50 pm 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Hi [VxE],

Yes, I thought about using an array for just that reason, although I was going to use a loop to build the array. If I go with the array, your suggestion of using StringSplit to create the array seems the easiest way.

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2007, 11:02 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
a stringsplit and a loop of the stringsplit results is the same as a loop, parse.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 1:27 am 
Offline

Joined: October 21st, 2006, 7:00 pm
Posts: 21
Hi engunneer,

You wrote:
Quote:
a stringsplit and a loop of the stringsplit results is the same as a loop, parse.


The difference, I'm hoping, is that a stringsplit results in an "array", which would allow me to address individual lines (so I can append the next line to the current line and increment the array index without using "continue"). If I use loop, parse, I haven't found any way to append the next line to the current line without iterating through the loop again.

Right?

Thanks,
John B.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 1:29 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
you are correct. I didn't read closely enough

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Azevedo, Google [Bot], JSLover, rbrtryn, tomL, vsub and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group