in reply to Extract portion of string based on string separator
You can use them for your current problem like this:sub path_parts(@) { shift=~m((/[^/]*))g } sub limit_list($@) { $#_=-1+shift; @_ }
my $orig_path = "/a/b/c/d/e/f"; my $trunc_path = join '', limit_list( 3, path_parts( $orig_path ) );
|
|---|