[EMAIL PROTECTED] wrote:
> 
> I have a list of names, separated by the '/' character in a variable, $list,
> and a name in the variable $name.  If the name appears in the list, I want to
> remove it and clean up $list.  It takes me 4 calls to s///, and it looks
> clunky.  I have a feeling that someone out there on this list will know a
> cleaner way to do it.
> 
> My code:
> 
> $list =~ s|$name||; # remove $name from the list if it's in the list
> $list =~ s|//|/|; # if $name was in the middle of the list, it would have
> left behind two /s, remove one
> $list =~ s|^/||; # if $name was at the front of the list, remove the leading /
> $list =~ s|/$||; # if $name was at the end of the list, remove the trailing /


$list = join '/', grep $_ ne $name, split /\//, $list;


Or of course, if the contents of $list is a file path then you should
use the File::Spec module.

use File::Spec;

$list = File::Spec->catdir( grep $_ ne $name, File::Spec->splitdir(
$list ) );




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to