in reply to split string and always get last word

this simple enough?
my $string = "./t2"; my $string2 = "/some/path/to/t3"; my $base = (split(/\//, $string))[-1]; my $base2 = (split(/\//, $string2))[-1]; print "$base\n$base2\n";

Replies are listed 'Best First'.
Re^2: split string and always get last word
by GrandFather (Saint) on Mar 02, 2006 at 03:50 UTC

    A two line equivelent example:

    my ($string, $string2) = ("./t2", "/some/path/to/t3"); print join "\n", map {(split /\//)[-1]} ($string, $string2);

    Prints:

    t2 t3

    This is about "get last word" isn't it :)


    DWIM is Perl's answer to Gödel