in reply to Re: Help with RC4
in thread Help with RC4

Thank you! I'd read that binmode wasn't needed on *nix systems -- apparently, I over interpreted what I read. Seems that what I needed was a combination of undef $/; and binmode(INFILE); and then $plaintext = <INFILE>. Binmode was also needed for the output file. thank you, thank you, thank, you! j.

Replies are listed 'Best First'.
Re^3: Help with RC4
by hbo (Monk) on Jul 26, 2004 at 06:04 UTC
    Hmm, binmode should not be needed on Linux (or Unix.) From perldoc -f binmode:
    Arranges for FILEHANDLE to be read or written in "binary" or "text" mode on systems where the run-time libraries distinguish between binary and text files..
    But the libraries on Unix-like systems make no such distinction. I'm guessing that the measures you took worked around the bug I mentioned below.

    "Even if you are on the right track, you'll get run over if you just sit there." - Will Rogers
      From `perldoc -f binmode', perl 5.8.4, emphasis mine
      On some systems (in general, DOS and Windows-based systems) binmode() is necessary when you're not working with a text file. For the sake of portability it is a good idea to always use it when appropriate, and to never use it when it isn't appropriate. Also, people can set their I/O to be by default UTF-8 encoded Unicode, not bytes.

      In other words: regardless of platform, use binmode() on binary data, like for example images.

      images, executables, zipfiles, tarballs, encrypted ...

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        Well, yeah, but that's for the sake of portability with OSen that do make the distinction between text and binary. Unix (and Linux) make no such distinction. Also, his data is good 'ol 7-bit ASCII. Why should he have difficulty reading that regardless of binmode? And why should setting LANG to 'C' address the problem? (I've tested it. It does.)

        It's a bug. It's either a Perl bug in 5.8.0 or a bug in Red Hat's implementation on RHEL3. They have stepped up to fix this in U3. I've tested the patch that fixes the problem.

        "Even if you are on the right track, you'll get run over if you just sit there." - Will Rogers