.------[ [EMAIL PROTECTED] wrote (2002/12/11 at 14:49:15) ]------
|
| 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 /
|
`-------------------------------------------------
How about this:
$list =~ s|/$name||;
$list =~ s|^/||;
If it's at the end, it will remove the last /.
If it's in the middle it will fill in correctly.
If it's on the front the second regex will take care of it.
---------------------------------
Frank Wiles <[EMAIL PROTECTED]>
http://frank.wiles.org
---------------------------------
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]