On Mon,  4 Jun 2001 14:57:28 -0400
 David Gilden <[EMAIL PROTECTED]> wrote:
> Is version 2 a better choice here?
> # desired result ""bill gates the third"
> $name= "bill_gates_the_third_132506042001.html";
> # vers 1:
>     $name =~ s/^(\w+?)_(\d+).html$/$1/;
>     $name =~ tr/_/ /;
> # vers 2:
>  $name =~ s/\d+.html$//;
>  $name =~ tr/_/ /;
>  $name =~ s/\s$//;

If you consider "shorter" to be "better" then here's a one-liner to do
it (the "e" flag causes Perl to evaluate the right side of the regex as
code).

$name= "bill_gates_the_third_132506042001.html";

$name =~ s/(^\s*|_\d+\.html\s*$|_)/" " if ($1 eq "_")/ge;
print $name; # bill gates the third

--
michael
<perlcircus.com>
_________________________________________________________
Get Free Email Served From a Mac at http://www.MacBox.com

_____________________________________________________________
Create Your Own Free Email Service at http://MailBranding.com

Reply via email to