Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!cs.utexas.edu!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: perl version of from(1) Message-ID: <1991May20.181507.13801@convex.com> Date: 20 May 91 18:15:07 GMT References: Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 59 Nntp-Posting-Host: pixel.convex.com From the keyboard of subbarao@phoenix.Princeton.EDU (Kartik Subbarao): :Anyone know of a cooler way to do this? : :#! /usr/princeton/bin/perl : :open(mail, $ENV{'MAIL'}) || exit; : :while () { : if (/^From /) { # Note this is different from From: : chop ($out = $_); print $out; : while () { : if (/^$/) { : print "\n"; : last; : } : if (/^Subject:/) { : chop; : @subj = split(/[: ]/,$_); : print ' "'.$subj[2].'"'."\n"; : last; : } : } : } :} Cooler? Hmm... Well, here's you I added: default open to /usr/spool/mail/$USER unless $MAIL set accept command line arguments for from filters make everything line up prettier be case insensitive strip local domain from hostname don't stop on first subject line lest there be more removed unneeded split and chops reduced the line count by 4 for job security through obscurity :-) Here's the code: #!/usr/bin/perl open (MAIL, $ENV{'MAIL'} || '/usr/spool/mail/'.$ENV{'USER'}) || exit; $only = join('|', @ARGV); $domain = '\.convex\.com'; while () { if (s/^from\s+//i) { # start of message @ARGV && (/$only/io || next); s/$domain//io if $domain; printf "%-18s %-25s", /(\S+)\s+(.*)/; while () { /^$/ && (print("\n"), last); s/^subject:\s*(.*)\n$/"$1"/i && print; } } } --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "So much mail, so little time."