in reply to How to sent binary data in socket programming ?
Hi bh_perl,
say
substr+lc crypt(qw $i3 SI$),4,5
Check out the module MIME::Base64. Specifically, you can encode your data with encode_base64 and decode it with decode_base64. For example:
Update: Fixed broken links; corrected script wording.#!/usr/bin/perl -w use strict; use warnings; use MIME::Base64; my $binary = ""; # Create binary data for (my $i = 0; $i < 256; $i++) { $binary .= chr($i); } my $blen = length($binary); print "Binary data is $blen bytes\n\n"; # Encode the data so that it's printable my $enc = MIME::Base64::encode($binary); my $elen = length($enc); print "Encoded data is $elen bytes:\n"; print "$enc\n"; # Decode the data back to binary, compare against original my $dec = MIME::Base64::decode($enc); my $dlen = length($dec); print "Decoded binary is $dlen bytes\n"; if ($dec eq $binary) { print "Decoded data matches original\n"; } else { print "Decoded Data MISMATCH with original\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to sent binary data in socket programming ?
by bh_perl (Monk) on Jul 14, 2013 at 06:51 UTC | |
by golux (Chaplain) on Jul 14, 2013 at 11:21 UTC | |
by bh_perl (Monk) on Jul 15, 2013 at 01:34 UTC |
In Section
Seekers of Perl Wisdom