computing
  • 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

-Nimika

Share

1 Answer

  1. A way ….

    #!/usr/bin/perl

    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