Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
eval 'exec perl -x $0 ${1+"$@"}' # -*-perl-*- if 0; #!perl -w # # "Pager" for PerlMonks # Gets personal messages and displays or mails them. # # Diego Zamboni, September 10, 2000 # # $Id: pmpager.pl,v 1.1.2.2 2000/09/10 17:44:20 zamboni Exp $ # use strict; use PerlMonks::Chat; use Text::Wrap qw(wrap); use Getopt::Long; use Mail::Mailer; use SDBM_File; use Fcntl; sub usage { return <<EOM; Usage: $0 [options] --login user -l user User to login as. Only needed once, it gets stored in a cookie --password pwd -p pwd Password to use (otherwise ask) --mailto addr -m addr Mail results (print to stdout by defaul +t) --checkoff -c Check off new messages automatically --ignorecache -i Print all messages, even if they have been seen before. By default it only sh +ows new messages --help -h This message EOM } my $p=PerlMonks::Chat->new(); $p->add_cookies(); # Config options my $user; my $mailto; my $passwd; my $checkoff; my $nocache; my $help; # Get command-line args GetOptions('login|l=s' => \$user, 'mailto|m=s' => \$mailto, 'password|p=s' => \$passwd, 'checkoff|c' => \$checkoff, 'ignorecache|i' => \$nocache, 'help|h' => \$help, ) or die usage(); warn(usage()), exit if $help; if ($user) { unless ($passwd) { $|=1; print "Password? "; $passwd=<STDIN>; } # Login $p->login($user, $passwd) or die "Login failure: $@\n"; } # Open the cache. my %cache; tie(%cache, 'SDBM_File', "$ENV{HOME}/.pmpager", O_RDWR|O_CREAT,0640); my $body=""; my @ids=(); # Get personal messages my %msgs=$p->personal_messages; foreach my $k (keys %msgs) { next if (!$nocache && exists($cache{$k})); $cache{$k}=1 unless $nocache; push @ids, $k; $body.=wrap("", "\t", $msgs{$k})."\n"; } untie %cache; # Print or send the messages if ($mailto) { if ($body) { my $mailer=Mail::Mailer->new(); $mailer->open({From => $mailto, To => $mailto, Subject => "Your new PerlMonks personal messages" }) or do { # This is so that if you execute this through crontab and # it fails, maybe you'll get your messages anyway. warn "Can't open Mail::Mailer object.\n"; warn "Your new personal messages are:\n$body"; die "Terminating.\n"; }; print $mailer $body; if ($checkoff) { print $mailer "\nThese messages have been checked off.\n"; } $mailer->close(); } } else { if ($body) { print "Your new PerlMonks personal messages:\n$body"; if ($checkoff) { print "\nThese messages have been checked off.\n"; } } else { print "No new personal messages.\n"; } } # Check off the messages if necessary. We do this last so that # if anything fails, the messages are not checked off. $p->checkoff(@ids) if @ids && $checkoff;

In reply to PerlMonks pager by ZZamboni

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2015-07-04 08:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (58 votes), past polls