home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6943 < prev    next >
Encoding:
Internet Message Format  |  1992-11-11  |  2.4 KB

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