On Mon, 13 Dec 2004 14:46:13 -0800 (PST), Christopher Spears <[EMAIL PROTECTED]> wrote: > Hi! > > Let's say I have a text file filled with: > > stuff > stuff > stuff > Users sometext > tom > dick > harry > Users more sometext > larry > curly > moe > moe > stuff > stuff > etc. > > I need to write a Perl script that will go through the > file and find the lines with Users, process that line, > and then start looking for moe (who may occur more > than once). Upon finding another line with Users, the > code should loop and process the line and then start > looking for moe again. How should I proceed?
You text example leaves something to the imagination. >From the text above, and your requirements, it seems like you can just search the whole file for 'moe'. When does a 'Users'-part end? I'm guessing occurences of 'moe' outside a "Users"-part shouldn't be handled? Not really sure if this a valid way to do it, I've never nested reads on the same filehandle myself. ## loop over file while( <FH> ) { ## Check for users part if ( /Users/i ) { ## Loop over users part (Is this considered bad form?) while( <FH> ) { ## Check for end of Users last if /endofUserspart/; ## Check for moe if ( /moe/i ) { ## We have moe inside users } } } } Tor -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>