in reply to Re: (bbfu) Re: Messing with (my head) a substring
in thread Messing with a substring
A few points of explanation: $paths[-1] means the last element of the array. The tr function returns the number of characters it transformed. The rindex function returns the character number where a substring last appears and the substr function returns part of a string. The push function adds items to the end of an array.my $str = "/One/Two/Three"; my @paths = ($str); while ($paths[-1] =~ tr#/#/# > 1) { push @paths, substr($paths[-1], 0, rindex($paths[-1], '/')); } print "$_\n" for @paths;
All these things are in the documentation that comes with perl, you just have to put them together.
|
---|
Replies are listed 'Best First'. | |
---|---|
(bbfu) (substr and rindex) Re(4): Messing with (my head) a substring
by bbfu (Curate) on Apr 02, 2001 at 03:39 UTC |