Gossamer Forum
Home : General : Perl Programming :

code problem : sub build_clean

Quote Reply
code problem : sub build_clean
This code turns "Name1/Name2/Name3" into "Name1 : Name2 : Name3", but I would like that this code would turn in into "Name3" only!

So: Just the last word, if you read backwords! Who Can help me out ? Please...

Code:
sub build_clean {

my ($input) = shift;
$input =~ s,/, : ,g; # Change '/' to ' : '.
return $input;
}


[This message has been edited by ds (edited February 20, 1999).]
Quote Reply
Re: code problem : sub build_clean In reply to
Hi,

Try:

Code:
sub build_clean2 {
# ------------------------------------
my $input = shift;
my ($last) = $input =~ /[^/](.+)$/;
return $last;
}

Cheers,

Alex