#!/usr/bin/perl -w # Thanks to folks on comp.lang.perl.misc for a few tips. use strict; use Convert::UU qw/uudecode/; die "Filename required\n" unless $ARGV[0]; my $file = shift; print "Parsing $file ...\n\n"; open (FILE, "<", $file) or die "Can't open file for reading: $!\n"; my ($data, $tempfile, $tempmode); MAIN: while (<FILE>) { next MAIN unless /^begin / .. /^end\s+/; INNER: { # extract the filename. If we already have a filename, it's a pos +sible short file in the data file, so reset everything. Could all of +this be done better somehow? if ( /^begin / ) { if ($tempfile) { print "Warning: possible short file $tempfile found\n\n"; $data = ''; } # if ($tempfile) ($tempmode, $tempfile) = ( /\Abegin (\d+) (.*)$/m); last INNER; } # if ( /^begin/ ) last INNER if /^end\s+/; # Last line of data. next MAIN if /[a-z]/; # Skip non-data lines next MAIN if /^\s+$/; # And again } #end of INNER $data .= $_; if ( /^end\s+/ ) { my $filename = $tempfile; my $mode = $tempmode; print "Found uuencoded file $filename\n"; my $outstr = uudecode($data); if (-e $filename) { print "Error, $filename already exists. Ignoring\n\n"; $data = ''; $tempfile = ''; $filename = ''; next MAIN; } open (OUTFILE, ">", $filename) or die "Can't open $filename for writing: $!\n"; print "Writing to $filename ...\n\n"; print OUTFILE $outstr; close OUTFILE; system ("chmod", $mode, $filename) and warn "Unable to change perms of $filename: $!\n"; $data = ''; $tempfile = ''; $filename = ''; } } close (FILE)

*BEEEP*

Code reposted on 4-27-02 so it doesn't appear to be double-spaced when viewed without code wrapping (I hope).

Bah! Updated again on 5-13-02, this time in Netscape, which hopefully won't insert extra ^Ms, like Opera does, apparently.


In reply to A better (?) uudecoder. by mephit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.