Robin Berjon wrote:
On Dec 15, 2008, at 21:53 , Johannes Plunien wrote:
My not very elegant, but working solution:
my $str = " Beta Launch Invites: Kwyno Brings The Web Into Your IM
And (Soon) SMS Inboxes ";
$str =~ s/^\s+|\s+$//g;
$str =~ s/\W/ /g;
$str =~ s/\s{1,}/ /g;
$str =~ s/\s/-/g;
$str = lc($str);
print "$str\n";
A wee bit shorter:
my $str = " Beta Launch Invites: Kwyno Brings The Web Into Your IM And
(Soon) SMS Inboxes ";
$str =~ s/^\s+|\s+$//g;
$str =~ s/\W+/-/g;
$str = lc($str);
print "$str\n";
Before putting that into a module though you might want to think about
what should happen to characters outside the [a-z0-9] range as \W will
match differently based on locale. I'm not sure what the recommended
behaviour is for such cases.
Here's some code I use for renaming strange files, there might
be something useful there (or not, given I'm decades behind on
this list)
use strict;
use Convert::Translit;
my $trans = Convert::Translit->new('Latin1' => 'ascii');
sub clean {
local($_) = shift;
$_ = $trans->transliterate($_);
$_=lc;
s/&/ and /g;
s/\+/ plus /g;
s/'//g;
y/()~/---/s;
# . || - || _ for the rest
s/(?:(-)|(\.)|[\W_])+/$+||'_'/ge;
s/^[._-]//;
s/[._-]$//;
return $_;
}
--
To treat a person harshly is the way of middle-classed lackeys.
-- Hagakure http://bereft.net/hagakure/
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/