Perl

Image sizes in Perl

If you need for figure out the size of an image, fetch Image::Size from CPAN , it’s just what you need. The module recognizes the most common image-formats such as JPG, GIF, PNG, PSD, TIFF and plenty more. The interface is simple and will get you what you need with no trouble at all. #!/usr/bin/perl -w use strict; use Image::Size; # Just fetch the size my ($size_x, $size_y) = Image::Size::imgsize('test.

Fetching available newsgroups from a news server

This script fetches a list of available newsgroups (and descriptions) from a news server. The group list is returned as a hashref where the keys are the groupname and the value is a description of the group. #!/usr/bin/perl -w use strict; use Net::NNTP; use MIME::Base64 qw(decode\_base64); use MIME::QuotedPrint qw(decode\_qp); my $server= "sunsite.auc.dk"; print STDERR "connecting to $server... "; my $nntp= Net::NNTP->new($server); unless($nntp) { print STDERR "failedn"; exit 1; } print STDERR "okn"; print STDERR "getting messages.

Fetching recent headlines from a news server

The followig piece connects to a news-server and fetches subjects from the last week in a specific newsgroup (the Danish perl-newsgroup) and prints these. #!/usr/bin/perl -w use strict; use Net::NNTP; use MIME::Base64 qw(decode\_base64); use MIME::QuotedPrint qw(decode\_qp); my $server= "sunsite.auc.dk"; print STDERR "connecting to $server... "; my $nntp= Net::NNTP->new($server); unless($nntp) { print STDERR "failedn"; exit 1; } print STDERR "okn"; print STDERR "getting messages... "; my $newstuff= $nntp->newnews(time - 7\*24\*2600, "dk.edb.programmering.perl"); unless($newstuff) { print STDERR "failedn"; exit 1; } print STDERR "okn"; my @messages; foreach my $msgid (@$newstuff) { my $head= $nntp->head($msgid); next unless $head; my %msg; push @messages, %msg; foreach(@$head) { next unless /^(Newsgroups|Subject|From):s+(.

Mark all messages as read in an imap folder

The follow script marks all files in a folder as read. You need to pass hostname, username and password as commandline parameters to the script and the script is hardwired to mark all files in a folder call “INBOX.spam” (Cyrus IMAP folder naming convention). #!/usr/bin/perl -w use strict; use Mail::IMAPClient::BodyStructure; use Mail::IMAPClient; my ($serv, $usr, $pwd) = (@ARGV); # server, username and password as comandline parameters... my $imap = Mail::IMAPClient->new(Server=>$serv,User=>$usr,Password=>$pwd); my @folders = $imap->folders; foreach my $f (@folders) { print "$f is a folder with ", $imap->message\_count($f), " messages.

Parsing RSS feeds

del.icio.us is a neat service for managing an online bookmark collection. With a little bit of Perl and a few CPAN modules, you can fetch your most recent bookmarks and include them as links on your homepage. The sample script could be used in a cronjob and creates a file on you local server. It downloads my del.icio.us bookmark feed, chops it down to the ten most recent bookmarks and writes a unordered bullet list.