jepri has asked for the wisdom of the Perl Monks concerning the following question:

I've been kicking around a program (will post soon) and I wanted to run it on something big... like the kernel source (unzipped, but still tarred into one file).

But Perl quits after reading the first entry in the file. I'm guessing there's a character there that makes it think that it's the EOF. I tried catting to <> and I tried sysread, but it still stops at the same point. Vi and less can read it.

How can I make perl read past the characters?

____________________
Jeremy
I didn't believe in evil until I dated it.

  • Comment on Reading past EOF characters in tar files?

Replies are listed 'Best First'.
Re: Reading past EOF characters in tar files?
by Cubes (Pilgrim) on Jul 24, 2001 at 08:45 UTC
    Does it quit at the same character ('od -c' is your friend here), or the same line or byte position in the file? What about other files, with different data? What happens if you construct a file with the suspect character in different positions, and feed that in?

    A code snippet of at least the part that's quitting on you would be helpful, as would some readable representation of the data it's choking on.

      Sorry, OK, my bad. It's the while loop quitting. But why does this:

      while (my $char = &getchar ) {

      return false when $getchar returns a \0 ? It's still a successful assignment, so I thought it would be true.

      BTW thanks for the tip about od. I hadn't seen that one before.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.

        Without looking things up, I'm thinking that because the value being assigned (and thus the value of the assignment) is zero, the conditional is turning up false. I think what you really want to do is test the gotten char against the empty string.
        What does getchar return? Does it return a number (the numeric value of the character) or a string with the character?

        In any event, you're going to have problems with that test. If getchar returns the numeric character value, it's going to stop at the first NUL (0) character. If it returns the character itself, it'll stop if the character is "0" (0x30).

      Aside: for those of you who use vim, you have a snazzy little tool called xxd that does all the stuff od -c does, and then some.

      xoxo,
      Andy
      --
      <megaphone> Throw down the gun and tiara and come out of the float! </megaphone>

Re: Reading past EOF characters in tar files?
by HyperZonk (Friar) on Jul 24, 2001 at 08:42 UTC
    Update: Nevermind, this was bad advice. (Re: binmode)

    -HZ
      Thanks, but I don't think binmode does anything on Linux installations. In this case, it doesn't help.

      ____________________
      Jeremy
      I didn't believe in evil until I dated it.