home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!zaphod.mps.ohio-state.edu!cs.utexas.edu!uwm.edu!ogicse!reed!romulus!merlyn
- From: merlyn@ora.com (Randal L. Schwartz)
- Newsgroups: comp.lang.perl
- Subject: Re: UUDECODE and perl ...
- Message-ID: <MERLYN.92Nov11094326@romulus.reed.edu>
- Date: 11 Nov 92 17:43:29 GMT
- Article-I.D.: romulus.MERLYN.92Nov11094326
- References: <1992Nov10.231657.17411@morwyn.uucp>
- <1992Nov11.134119.15928@porthos.cc.bellcore.com>
- <1992Nov11.150851.10057@news.eng.convex.com>
- Sender: news@reed.edu (USENET News System)
- Organization: Stonehenge Consulting Services; Portland, Oregon, USA
- Lines: 52
- In-Reply-To: tchrist@convex.COM's message of 11 Nov 92 15:08:51 GMT
-
- In article <1992Nov11.150851.10057@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
- You shouldn't have to open a pipe to uudecode. unpack('u', $datum)
- should suffice.
-
- In fact, here's my program that uudecodes, ignoring anything that's
- not a legal part of the uudecode. I call it "uumerge". There are
- *many* broken uuencoders out there on the net, which is why it goes
- through all these gyrations to figure out what the legal uu-lines are.
- Ugh.
-
- #!/local/usr/bin/perl
-
- ## Version 1.09 on 92/02/25
- ## Written by Randal L. Schwartz, Stonehenge Consulting Services, Portland, OR
- ## uudecodes the arguments (or stdin), ignoring non-uuencoded lines
-
- shift,$debug++ if $ARGV[0] =~ /^-d/; # show lines being skipped
- while (<>) {
- last if ($mode,$file) = /^begin\s*(\d*)\s*(\S*)/;
- }
- die "missing begin" unless $_;
- open(OUT,"> $file") if $file ne "";
- while (<>) {
- last if /^end/;
- $u = unpack("u",$_);
- $p = pack("u",$u);
- $p =~ s/`*\n//; # toss trailing open quotes and newline
- # $p now has the shortest line that might appear in the file
- $lp = length($p);
- if (
- (!/^--/) && # hack for not a cut line
- (!/^#/) && # hack for not a shar tag line blech
- (!/^CREATED BY/) && # hack for a stoopid losing uusplitter
- ($lp < length) &&
- (substr($_,0,$lp) =~ /^[\020-\140]+$/) &&
- (substr($_,$lp) =~ /^[` ]*.?.?$/) # two garbage chars ok
- ) {
- print OUT $u;
- print "$_","=" x $lp, "\n" if $debug;
- } else {
- print "skipping: $_" if $debug;
- }
- }
- die "missing end" unless $_;
- chmod oct($mode), $file;
- exit 0;
-
- print unpack(u,q|92G5S="!A;F]T:&5R(%!E<FP@:&%C:V5R+```|)
- --
- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
- merlyn@ora.com (semi-permanent) merlyn@reed.edu (for newsreading only)
- factoid: "Portland, Oregon, home of the California Raisins and Lone-Star Beer!"
-