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

Can someone tell me if this is a natural occurrence, or possibly something I'm doing wrong.

I've got a 72 byte hex string that I'm trying to encode and at the 77th byte it keeps putting a newline character.

Example:
hex: f89b1c0a34d7ab5446368c48107fff2a138baf8650d6c6464518c3f0d4c850083d8b1d30
base64: Zjg5YjFjMGEzNGQ3YWI1NDQ2MzY4YzQ4MTA3ZmZmMmExMzhiYWY4NjUwZDZjNjQ2NDUxOGMzZjBk
NGM4NTAwODNkOGIxZDMw

Am I going to need to run a regex on this or is it just the emulator and web browser that produces this?

Thank you,
deMize


Try it yourself:
#!/yourpath/perl use MIME::Base64; use Strict; my $s_enc = "f89b1c0a34d7ab5446368c48107fff2a138baf8650d6c6464518c3 +f0d4c850083d8b1d30"; print encode_base64($s_enc) . "\n";



As you can tell I'm a Perl neophyte..a Perlophyte! so please go easy on me

Replies are listed 'Best First'.
Re: MIME::Base64 Question
by GrandFather (Saint) on Mar 02, 2009 at 19:01 UTC

    From the MIME::Base64 docs:

    Encode data by calling the encode_base64() function. The first argument is the string to encode. The second argument is the line-ending sequence to use. It is optional and defaults to "\n". The returned encoded string is broken into lines of no more than 76 characters each and it will end with $eol unless it is empty. Pass an empty string as second argument if you do not want the encoded string to be broken into lines.

    True laziness is hard work
      Adding the '' works. Thanks a lot.

      I was aware of the second parameter, but I thought this had to do with the final line termination, not midway through the encoded string.


      Thank you all for your help.
MIME::Base64 Question
by deMize (Monk) on Mar 02, 2009 at 18:39 UTC
    use MIME::Base64;

    my $s_enc = "f89b1c0a34d7ab5446368c48107fff2a138baf8650d6c6464518c3f0d4c850083d8b1d30";

    print encode_base64($s_enc) . "\n";

    ---------------
    Outputs:
    Zjg5YjFjMGEzNGQ3YWI1NDQ2MzY4YzQ4MTA3ZmZmMmExMzhiYWY4NjUwZDZjNjQ2NDUxOGMzZjBk
    NGM4NTAwODNkOGIxZDMw

    20090307 Janitored by Corion: Restored content

      The doc says:
      Pass an empty string as second argument if you do not want the encoded string to be broken into lines.
      Anno