-4

I want to use Perl to split the path

funit/pipe/str/str32/gt/split

up to

funit/pipe/str/str32/gt

using a regular expression.

Borodin
  • 126,100
  • 9
  • 70
  • 144
  • Welcome to StackOverflow. Please take the [tour], learn asking good questions stackoverflow.com/help/how-to-ask, make a [mcve]. An MCVE should include a variety of sample input (illustrating all aspects) and desired output. Please show your own coding attempts. – Yunnosch May 28 '17 at 15:00
  • 4
    What have you tried? What problems are you having? Please show us your code (if you don't have any code, then Stack Overflow is probably the wrong place to be asking this question). – Dave Cross May 28 '17 at 16:42

1 Answers1

1

It looks like you just want the path to the parent directory; is that right? I wouldn't call it "splitting" the path

Is the restriction on using a regex pattern a genuine one, or did you just think it would be the best method?

Here's a program that uses Path::Tiny to do what you ask

use strict;
use warnings 'all';
use feature 'say';

use Path::Tiny;

my $path = Path::Tiny->new('funit/pipe/str/str32/gt/split');

say $path;
say $path->parent;

output

funit/pipe/str/str32/gt/split
funit/pipe/str/str32/gt
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • This doesn't look like regex, I do have same question however I need to use it to configure nginx – AaA Oct 20 '20 at 02:31