Re: Reading file issue



On 2008-02-28, sharon@xxxxxxxxxxxxxxxxxxx <sharon@xxxxxxxxxxxxxxxxxxx> wrote:
I have an issue that puzzles me, I f anyone can point me to the
documentation it will be great.
I'm writing a file and reading it right after. the results I'm getting
from reading the file are different then what I expect.

This is not a very clear error description. Are you sure the file
contains what you want? Perhaps you have written out the wrong data,
and reading it back is working fine. (In this case that's not true, but
you need to specify what's broken, and how you know.)

#!/usr/bin/perl
use strict;

use warnings;

while (<NewSCAL>){
my $line = <NewSCAL>;
print $line;
}

This loop is reading a line from NewSCAL, discarding it, reading the
next line and putting it into $line, printing it, then redoing the loop
till the lines are exhausted. So you're discarding every other line.
The idiomatic way to write your loop is

print while <NewSCAL>;

If you wish to process each line somehow, you'd do

while (my $line=<NewSCAL>)
{
# do stuff to $line, including possibly printing it
}

the results are:

[over 1100 lines snipped]

Don't do that! Post *example* inputs and/or outputs which replicate
your problem. Please read the Posting Guidelines which are posted here
quite frequently.

--keith

--
kkeller-usenet@xxxxxxxxxxxxxxxxxxxxxxxxxx
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information

.



Relevant Pages

  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)
  • Re: advice and/or help on glReadPixels
    ... I could not see any "BRGA" in the documentation. ... Is it possible that some cards are not ... >>> a) Try reading the entire RGB instead of just the red. ... a quick integer loop with a mask & shift is ...
    (comp.graphics.api.opengl)
  • Re: while (1) vs. for ( ;; )
    ... >to write to the next guy who will be reading the code. ... You are unfamiliar with the term "infinite loop"? ... Balmer Consulting ...
    (comp.lang.c)
  • Re: Stopping program execution in another thread
    ... I assume from your comments, and reading the articles, it can not easily be ... done, and I am better off using the loop, and doevents. ... I know I can do this with the doevents, ...
    (microsoft.public.vb.controls)