This is my first Perl script. Perl is not my first programming language, though.
This script is cobbled together from various sources. I was using Perlcritic and Perltidy to help writing idiomatic code. You guys did a great job with those tools.
#!/usr/bin/perl # read emails I sent myself containing just a link # and make a HTML-redirect based bookmark out of them # # SPEC # read given files as internet messages # use subject as title and filename, escape as needed # use one URL in body as href (if there a two they are both the same) # and output one HTML file for each bookmark use strict; use warnings; use Encode; use Path::Tiny; use Email::Simple; use HTML::Entities; use URI::Find; use version; our $VERSION = qv('0.0.1'); foreach my $in_filepath (@ARGV) { my $in_file = Path::Tiny->new($in_filepath)->slurp; my $message = Email::Simple->new($in_file); my $subject = decode( 'MIME-Header', $message->header('Subjec +t') ); my $title = HTML::Entities::encode($subject); my $out_filepart = $subject =~ s/[%\/\?<>\\:\*\|":]/_/gr; my @uris; # TODO URL::Search might be nicer than URI::Find for some cases # TODO $finder = URI::Find->new(sub { push @uris, $_[0] }); my $finder = URI::Find->new( sub { my $uri = shift; push @uris, $uri; }, ); $finder->find( \$message->body ); path("$out_filepart.URL.HTML") ->spew( "<!DOCTYPE html><title>$title</title><meta http-equiv=\" +refresh\" content=\"0; url=$uris[0]\">" ); }
The script does what it is supposed to do. I'm looking for any kind of feedback, especially pitfalls and 'better' idioms etc. I already got some feedback I put in as 'TODO'
Some musings about the choices I made:
Overall I'm okay with how it turned out for the first one. It's not that big of a script after all anyways. So: critique away :)
In reply to Please critique this script -- Read emails and write URLs into bookmarks by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |