Perl regex to parse a variable for the dir and filename

I have a problem on a web form. The form is passing a variable to either a full or relative path on the system. If the path doesn't exist the I need to create the dir (after some checking, etc) so that a file can be uploaded to it.

So the called to filename and basename will not work since they expect existing valid paths.

I was thinking that something like:

my $dirpath = $setpath;
$dirpath =~ s/\/(.*?\/)//;

would just remove the file name and leave me with the dir. But alas it just returns the string. :(
bs98909Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
my ($dirpath,$filename) = $setpath =~ /(.*\/)(.*)/;
0
 
bs98909Author Commented:
That was it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.