I have a need for a good perl module to convert an article title to a nice URL string. For example
'I am a mean perlmonk.' => 'i-am-a-mean-perlmonk',
'RFC: Module to take a title and generate the core bit of the URL' => 'rfc-module-to-take-a-title-and-generate-the-core-bit-of-the-url',
'I have deep-seated emotional problems!' => 'i-have-deep-seated-emotional-problems'
'Sacrificing minions: is there any problem it can't solve?' => 'sacrificing-minions-is-there-any-problem-it-cant-solve'
I find it hard to believe that nothing on CPAN attempt to solve this problem. The following code does a reasonable job on the easy cases:
$title =~ s{\s}{_}g;
$title =~ s{\/}{_}g;
$title =~ s{\W}{}g;
$title =~ s{_}{-}g;
return lc($title);
However it needs to do a lot better. It falls up over entities such as '’'. It needs to know about UTF8 and be able to distinguish between exotic letters and exotic punctuation. In some cases it should give up and throw an exception. Does anyone know a module that already does this. I have tried searching CPAN but found nothing.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.