Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!rpi!bu.edu!nntp-read!composer From: composer@chem.bu.edu (Jeff Kellem) Newsgroups: comp.lang.perl Subject: Re: Uudecode in Perl? Message-ID: Date: 2 Sep 90 16:56:08 GMT References: Sender: news@bu.edu.bu.edu Reply-To: composer@chem.bu.edu Organization: Boston University Chemistry Department Lines: 48 In-reply-to: cybrspc!roy@cs.umn.edu's message of 2 Sep 90 09:09:06 GMT In article cybrspc!roy@cs.umn.edu (Roy M. Silvernail) writes: > Date: 2 Sep 90 09:09:06 GMT > > Has anyone implemented UUdecode in Perl? As of version 3.0 patchlevel 28 of perl, uu{de,en}coding is builtin to perl via the `pack' and `unpack' functions. Actually, it's in there at patchlevel 27, but pl28 came out quickly afterwards fixing some problems in perl, so you should be at pl28. ;-) Here's a quick example of uudecode in perl using those features. Implementing uuencode would follow along similar lines. As Larry said in the patch comments, it was a "wacked out evening" when he added this feature. :-) Enjoy... -jeff Jeff Kellem Internet: composer@chem.bu.edu p.s. It's just something quickly thrown together.. something can always be done better. #!/usr/bin/perl # # quick uudecode -- no error checking ($version,$patchlevel) = $] =~ /(\d+\.\d+).*\nPatch level: (\d+)/; die "Uu{de,en}coding not builtin to perl till version 3.0 pl27.\n" if $version * 1000 + $patchlevel < 3027; while (<>) { if (/^begin\s(\d+)\s(.*)/) { $file = $2; $mode = "0" . $1; open (INPUT, "> $file") || die "Can't create $file: $!\n"; chmod oct($mode), $file; next; } close (INPUT), next if /^end/; $line = unpack("u",$_); print INPUT $line; }