Loading ...
Sorry, an error occurred while loading the content.

Binary Printing

Expand Messages
  • gadgetseeker
    I need to print data to a file in binary format. Any n should be printed as-is without being converted to a new-line character. I tried the following code,
    Message 1 of 3 , Jun 24 9:07 PM
    • 0 Attachment
      I need to print data to a file in binary format. Any "\n" should be
      printed as-is without being converted to a new-line character.

      I tried the following code, but all instances of the "\n" were
      coverted to new-line characters.

      -----------------------------------------------
      #!/usr/bin/perl
      open($fh,'>','temp.txt');
      binmode($fh);
      select($fh);
      print "ABC\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nXYZ";
      close($fh);
      -----------------------------------------------

      I also tried the following line to no avail:
      open($fh,'>:raw','temp.txt');


      Any help will be appreciated.
    • merlyn@stonehenge.com
      ... gadgetseeker I need to print data to a file in binary format. Any n should be gadgetseeker printed as-is without being converted to a new-line
      Message 2 of 3 , Jun 25 4:59 AM
      • 0 Attachment
        >>>>> "gadgetseeker" == gadgetseeker <gadgetseeker@...> writes:

        gadgetseeker> I need to print data to a file in binary format. Any "\n" should be
        gadgetseeker> printed as-is without being converted to a new-line character.

        gadgetseeker> I tried the following code, but all instances of the "\n" were
        gadgetseeker> coverted to new-line characters.

        Since, by definition, "\n" *is* the newline character, why do you want
        Perl to do something other than what you told it, and what might that be?

        --
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      • gadgetseeker
        Clarification of my original query: I am going to print a LARGE volume of raw binary data to a file. Prior to printing, the data will be in strings that my
        Message 3 of 3 , Jun 25 6:35 AM
        • 0 Attachment
          Clarification of my original query:

          I am going to print a LARGE volume of raw binary data to a file. Prior
          to printing, the data will be in strings that my program will construct
          on-the-fly. I want to make sure that *IF* the string \n appears
          ANYWHERE in the raw binary data strings, that it will NOT be converted
          to a new-line character (ascii 10).

          The code I posted was simply a test to see what would give me the
          desired effect.

          Thanks for all who have responded or will respond.
        Your message has been successfully submitted and would be delivered to recipients shortly.