[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

how to capture a directory structure and the file name in a string in Perl?

Hi,
I have a string as the following:

See 20120816_1406_Report.html for details in //dir1/dir2/dir3/dir4/dir5/dir6 directory.

Open in new window


I would like to create another string from this string as the below:

//dir1/dir2/dir3/dir4/dir5/dir6/20120816_1406_Report.html

Open in new window


In general I need to catch the directory structure and the html file in this string basically.

Thanks,
0
Tolgar
Asked:
Tolgar
1 Solution
 
farzanjCommented:
my $str = 'See 20120816_1406_Report.html for details in //dir1/dir2/dir3/dir4/dir5/dir6 directory.';

my ($file, $path) = $str =~ m{(\w+\.html)[^/]+(//\S+)};

my $fullname = "$path/$file";

print $fullname;

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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