157

Input/Output
The Unpack Function

  • The unpack() function unpacks native binary data into Perl format

      $unpacked = unpack( TEMPLATE, LIST );

  • Same template characters used by the pack() function

  • Here's a complete uudecode program!
      while ( <> ) {
      	tr#A-Za-z0-9+/##cd;                    # Remove non-base64 chars
      	tr#A-Za-z0-9+/# -_#cd;                 # Convert to uuencoded format
      	$len = pack( "c", 32 + 0.75*length );  # Compute length byte
      	print unpack( "u", $len . $_ );        # uudecode and print
      }
      

  • Yes, you CAN write very cryptic code in Perl, but PLEASE don't...