in reply to Regular expression parse pathname
use strict; use warnings; my $s = '/home/code/work'; my @ds = split m{/}, $s; shift @ds; my $accum; for (@ds) { $accum .= "/$_"; print "$accum "; } print "\n";
Update: or, adapting your regex attempt:
my $s = '/home/code/work'; my $acc; while ($s =~ m#([^/]+)#g) { $acc .= "/$1"; print "$acc " }
|
|---|