This should be useful to authors of the Perl summaries and such, which was my main reason for making Metamark.
Beware that you need to install URI::Find and WWW::Shorten. WWW::Shorten requires about two billion other modules (mostly indirectly), so be sure to use the CPAN shell to install them.
# perl -MCPAN -e shell install URI::Find WWW::ShortenOh, and you can of course use one of the other shortening services that WWW::Shorten supports.
#!/usr/bin/perl -w use strict; # (this was in pod; but MovableType strips my '=cut' so I changed it to a comment) # # Read a text line by line from standard input; convert long urls to short metamark urls # and output to standard out. use WWW::Shorten 'Metamark', ':short'; use URI::Find; my $finder = URI::Find->new( sub { my($uri, $orig_uri) = @_; if( length $uri > 35 or $uri =~ m![^\w./_:?%]!) { return short_link($orig_uri) || $orig_uri; } return $orig_uri; } ); while (<>) { my $text = $_; $finder->find(\$text); print $text; } 1;
Leave a comment