String::Ident - clean-up string to be used as identifier and in URLs
my $ident = String::Ident->cleanup('Hello wœrlď!') is($ident,'Hello-woerld')
clean-up string to be used as identifier and in URLs
cleanup does the following things to convert your messy string into something that you can use as an identifier:
cleanup
# replace unicode by ascii $text = unidecode($text); # replace anything basides numbers, letters and dash by dash $text =~ s/[^-A-Za-z0-9]/-/g; # one dash is enough $text =~ s/--+/-/g; # no need to start or end with a dash $text =~ s/-$//g; $text =~ s/^-//g; # maximum length $text = substr($text,0,30); # min length is set to 4 filled in by random letters
cleanup per default truncates the text to 30 chars. You can pass in some other limit, or -1 to not truncate:
-1
cleanup("some very long töxt Lorem ipsum dolor sit amet, consectetur adipiscing elit, ", 15); # 'some-very-long-toxt-' cleanup("some very long töxt Lorem ipsum dolor sit amet, consectetur adipiscing elit, ", -1); # 'some-very-long-toxt-Lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit'
Jozef Kutej, <jkutej at cpan.org>
<jkutej at cpan.org>
The following people have contributed to the String::Ident by committing their code, sending patches, reporting bugs, asking questions, suggesting useful advises, nitpicking, chatting on IRC or commenting on my blog (in no particular order):
Andrea Pavlovic
Syohei YOSHIDA
Thomas Klausner, <domm@plix.at>
<domm@plix.at>
Thanks to VÖV - Verband Österreichischer Volkshochschulen for sponsoring development of this module.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install String::Ident, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::Ident
CPAN shell
perl -MCPAN -e shell install String::Ident
For more information on module installation, please visit the detailed CPAN module installation guide.