Solved

Perl regex to parse a variable for the dir and filename

Posted on 2009-06-28
2
278 Views
Last Modified: 2013-12-25
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. :(
0
Comment
Question by:bs98909
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 24732124
my ($dirpath,$filename) = $setpath =~ /(.*\/)(.*)/;
0
 

Author Closing Comment

by:bs98909
ID: 31597714
That was it!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question