• 0

Solved How To Strip Last Word From a String In Perl

  • 0

I have a string like a/b/c/d/e/f/god

how do i strip off last word “god” so the o/p is a/b/c/d/e/f



1 Answer

  1. A way ….


    use strict;
    use warnings;

    my $string = ‘a/b/c/d/e/f/god’;

    my @array = split /\//, $string;

    pop @array; # get rid of the last array element on right

    $string = join(‘/’, @array);

    print “$string\n”;

    • 0