Alex Rivera | Logout

How can I extract a filename from a path using Perl?

Asked 2011-01-22T11:25:36.353
22

I have a Perl variable I populate from the database. Its name is $path. I need to get another variable $file which has just the filename from the pathname.

I tried:

$file = $path =~ s/.*\///;

I am very new to Perl.

Edit
Report

1 Answer

3
use File::Basename 

Check the below link for a detailed description on how it works:

http://p3rl.org/File::Basename

answered 2011-01-22T11:30:03.517

Your Answer