#!/usr/local/perl5.002_01/bin/perl # Simple uudecode in perl, ripped from Convert-UU-0.52, Andreas J. König # Works only with files, not stdin/out. use strict; sub uudecode { my($in) = @_; my(@result,$file,$mode); $mode = $file = ""; local($\) = "\n"; binmode($in); while (<$in>) { if ($file eq "" and !$mode){ ($mode,$file) = ($1, $2) if /^begin\s+(\d+)\s+(.+)$/ ; next; } last if /^end/; push @result, uudecode_chunk($_); } wantarray ? (join("",@result),$file,$mode) : join("",@result); } sub uudecode_chunk { my($chunk) = @_; return "" if $chunk =~ /^(?:--|CREATED)/; my $string = substr($chunk,0,int((((ord($chunk) - 32) & 077) + 2) / 3)*4+1); my $ret = unpack("u", $string); defined $ret ? $ret : ""; } die "Usage: $0 file\n" unless @ARGV==1; open F, $ARGV[0] or die "Couldn't open $ARGV[0]: $!"; my($uudecoded_string,$file,$mode) = uudecode(\*F); open F, ">$file" or die "Can't open >$file: $!"; binmode(F); print F $uudecoded_string; close F; chmod oct($mode), $file;