I was kicking around university the other day when I ran into a guy who was signing up to have dictionary.coms word of the day emailed to him every day. This seemed like a very wasteful cluttering of the inbox to me and I thought this could be achieved a lot better by having a Gtk/perl script pop up the info every day.. The other night I got bored and nocked up a script. I am but a newcomer to the holy temple so please monks be hard of me and tell me how I could do this better... Here is what I came up with:
#!/usr/bin/perl # # Word Of The Day Catching Script... # (V0.1) # Joe Higton # # And hey I was half asleep when I wrote this.... # # Gets the word of the day from www.dictionary.com # # use Gtk; use HTTP::Lite; init Gtk; sub msbox{ # Display some info. Nicely. Ish. my ($title, $message) = @_; my $scroller = new Gtk::ScrolledWindow; my $window = new Gtk::Window; my $label = new Gtk::Label; my $button = new Gtk::Button("OK"); my $pack = new Gtk::Packer; $window->set_title($title); $window->set_default_size(400,340); $window->signal_connect( "destroy" => \&Gtk::main_quit); $button->signal_connect( "clicked" => \&Gtk::main_quit); $label->set_justify(left); $label->set_text($message); $scroller->add_with_viewport($label); $pack->add_defaults($scroller,-top,-center,[-fill_x,-fill_y,-expan +d]); $pack->add_defaults($button,-bottom,-center,[-fill_x,-fill_y]); $window->add($pack); $window->show_all(); } $http = new HTTP::Lite; $req = $http->request("http://www.dictionary.com/wordoftheday/") or die "Couldn't retrieve the Word Of The Day."; # Ok grab the important bit of the web page. Handily kept between two +comments. $http->body() =~ /<!-- Begin content -->(.*)<!--End content-->/s; $wod = $1; # Capture the actual word its self from the cunning comment.. $wod =~ /<!-- WOTD="(.*)" -->/; $theword =$1; #Kill that HTML! I actually stole this regex off perlmonks # because I was too bloody tired to think of one of my own at the #time.. $wod =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs; #Fire all that off into a nice window.. msbox("The Word Of The Day IS: $theword",$wod); Gtk->main();
"blue berry muffins are not just a snack.... ..they are a way of life"

Edit: chipmunk 2001-06-21


In reply to Dictionary.com (PLEASE critisise...) by Draxil

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.