Solved how to strip last word from a string in perl

June 6, 2013 at 21:28:47
Specs: sunOS

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


See More: how to strip last word from a string in perl

Report •

#1
June 7, 2013 at 07:32:01
✔ Best Answer
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";


Report •
Related Solutions


Ask Question