Hi,

I have a string like this:

$string ="datafiles/source/main_data_files/content.csv";
if($string=~/main_data_files\/(.*)\.csv/ig) {
print "\n matched-- $1\n";
}

I want to retrieve the csv file name i.e

content.csv

I tried with the above code i am getting the result but i want some other better performance matching part.

How can i get the csv filename?

Regards
Amit

Recommended Answers

All 2 Replies

Uhm split and take the last entry?

Another way, if you don't mind using a module:

#!/usr/bin/perl
use strict;
use warnings;

use File::Basename;

my $string ="datafiles/source/main_data_files/content.csv";
my $filename = fileparse($string);

print "\nThe file name is $filename\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.