Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Perl regex to parse a variable for the dir and filename

Posted on 2009-06-28
2
Medium Priority
?
294 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 85

Accepted Solution

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

Author Closing Comment

by:bs98909
ID: 31597714
That was it!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

916 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