cherio has asked for the wisdom of the Perl Monks concerning the following question:
alternatively a reversed array will do as well( /abc/def/ghi, /abc/def, /abc )
The following regex breaks path into up to 3 segments( /abc, /abc/def, /abc/def/ghi )
This regex is rigid. I can make it long enough to be able to break path into N segments but if the actual path has N+1 segments the regex won't work.my $path = "/abc/def/ghi"; my @segments = ($path =~ m'^(/[^/]+ (/[^/]+ (/[^/]+)? )? )'x);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Breaking file path into segments
by choroba (Cardinal) on Apr 12, 2019 at 20:23 UTC | |
by shawnhcorey (Friar) on Apr 15, 2019 at 14:31 UTC | |
by choroba (Cardinal) on Apr 15, 2019 at 14:48 UTC | |
|
Re: Breaking file path into segments
by holli (Abbot) on Apr 12, 2019 at 20:29 UTC | |
|
Re: Breaking file path into segments (updated x2)
by AnomalousMonk (Archbishop) on Apr 12, 2019 at 21:38 UTC | |
|
Re: Breaking file path into segments
by johngg (Canon) on Apr 13, 2019 at 11:01 UTC | |
|
Re: Breaking file path into segments
by Marshall (Canon) on Apr 15, 2019 at 04:29 UTC |