[comp.lang.perl] unpacker in Perl

merlyn@iwarp.intel.com (Randal Schwartz) (04/09/90)

In article <1990Apr9.005506.5778@utstat.uucp>, geoff@utstat (Geoff Collyer) writes:
| C news doesn't unpack maps automagically; you have to put something in your
| sys file.  Some people run uuhosts from their sys files for comp.mail.maps.

I've got this unpacker in Perl that I've been using for a few months.
I call it "map-unpacker", and leave it lying about in the map
directory.  Don't call it something that is a legal map name (like
"mapunpacker") or you will find it replaced someday with a trojan
horse!  (Legal mapnames are defined by the regex in the line following
"bad filename" below...)

================================================== cut here
#!/local/merlyn/bin/perl

$mapdir = "/usr/spool/news/comp.mail.maps";
umask 002;

chdir $mapdir || die "Cannot chdir $mapdir ($!)";

$exit = 0;

while (<>) {
	next unless /^cat << 'SHAR_EOF' > (\S+)$/;
	$SHAR = $1;
	(warn "bad filename: $SHAR"), $exit++, next
		unless $SHAR =~ /^[a-zA-Z0-9.]+$/;
	open(SHAR,">$SHAR") || warn "cannot open $SHAR ($!)";
	while (<>) {
		last if /^SHAR_EOF/;
		print SHAR $_;
	}
	close(SHAR);
}
================================================== cut here

My sys entry looks like:

ME-maps:comp.mail.maps/all::/usr/spool/news/comp.mail.maps/map-unpacker

Just another Cnews admin and Perl hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/