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

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.