what about if I wanted to move to the 10th element or 10th scaler as 
opposed to bytes or characters?  I want to go to scaler 10 then \n then 3 
more lines of 10 or less.
If there were exactly 40 lines then obviously 4 lines of 10, but less than 
40 first line = 10 and so on just as long each line does not exceed 10.

like so:

dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 
dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 
dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 
dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 

dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 
dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 
dsxxd edsxx edxxs eedx edsa edcsa

dsxxd edsxx edxxs eedx edsa edcsa ecdsd edsd eddds edsad 
dedd defde ddefde wefwerf edewfew 


thanks, 
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






David Arnold <[EMAIL PROTECTED]>
06/30/2004 05:52 PM

 
        To:     [EMAIL PROTECTED]
        cc:     [EMAIL PROTECTED]
        Subject:        Re: Searching ahead in a file


Japhy et al,

This worked perfectly for what I want to do.

Thanks to all of you, I am learning at a greater rate than by working 
alone.

Many thanks. 

At 04:32 PM 6/30/04 -0400, Jeff 'japhy' Pinyan wrote:
>On Jun 30, David Arnold said:
>
>>As I begin reading in lines from the file, I just print them until I hit 
a
>>line that has an opening "\ex" in it. At that point I want to accumulate
>>lines in one long string until I hit either "\begin{instructions}" or
>>another "\ex".
>>
>>$line.=<IN>   #unless the current line coming in from IN is the start
>>                                 #of a new \ex or a \begin{instructions}
>>
>>The difficulty is now I've read one line too many. I'd like to "put this
>>last line back" for the next round of reading while I process the
>>accumulated exercise lines.
>
>I would suggest the following approach:
>
>  # some bigger loop
>  while (...) {
>    my $line = "";
>
>    while (<IN>) {
>      if (/\\ex|\\begin{instructions}/) {
>        seek IN, -length, 1;
>        last;
>      }
>      $line .= $_;
>    }
>  }
>
>This uses the seek() function to go to a position in the file.  The last
>argument, 1, means we're moving relative to where we are now.  The middle
>argument, -length, is the number of bytes to move.  So if the line is 20
>characters long, we're going 20 characters back from where we are now,
>essentially to the start of the line.
>
>-- 
>Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
>RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
>CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me 
know.]
><stu> what does y/// stand for?  <tenderpuss> why, yansliterate of 
course.
>
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to