• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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. :(
0
bs98909
Asked:
bs98909
1 Solution
 
ozoCommented:
my ($dirpath,$filename) = $setpath =~ /(.*\/)(.*)/;
0
 
bs98909Author Commented:
That was it!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now