http://qs321.pair.com?node_id=331368
Category: GUI Programming
Author/Contact Info bhappy
Description: Perl is not the only language i'm learning right now, i'm also learning english ;)... i was looking for a little tool, which would stay on the top of my desktop and show english words with a translation changing them in every N seconds. i'm using FlashKard, coming with KDE, and i have alredy collected a little vocabulary. so i decided to make a script which would use a file created by FlashKard (xml) and show words randomly.
don't judge it too strictly, it's my first public code.
i would be happy to get any notices, corrections or additions.
#!/usr/bin/perl

=head1 NAME

kvread - Vocabulary memorization tool

=head1 SYNOPSYS

kvread [file name]

=head1 DESCRIPTION

kvread makes use of a vocabulary files created by KDE FlashKard. This 
+script shows words from a given file with a translation\
 randomly.

=head1 AUTHOR

bhappy

=cut

use strict;
use warnings;

use Tk;
use XML::Simple;
use Getopt::Long;

my $xml_file = shift;
my $words = XMLin($xml_file,
                  forcearray => [ qw(e) ],
                  keyattr => []
                  );

my $mw = Tk::MainWindow->new;
# $mw->overrideredirect(1);
my ($worde, $wordr) = &rand_n(\@{$words->{e}});
$mw->Label(-textvariable => \$worde, -background => 'pink', -font => '
+verdana')->pack;
$mw->Label(-textvariable => \$wordr, -background => 'lightblue')->pack
+;
$mw->update;
$mw->repeat(8*1000, sub{($worde, $wordr) = &rand_n(\@{$words->{e}})});

MainLoop;

sub rand_n {
    my ($words_ref) = @_;
    my $count = rand @$words_ref;
    my $worde = $words_ref->[$count]->{o};
    my $wordr = $words_ref->[$count]->{t};
    return ($worde, $wordr);
}