Solved

Perl regex to parse a variable for the dir and filename

Posted on 2009-06-28
2
275 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now