CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Remove extensiton from existing string

 



StarkRavingCalm
User

May 16, 2013, 11:11 AM

Post #1 of 3 (329 views)
Remove extensiton from existing string Can't Post

Hi all -

I am using an existing string for other requirements (i.e. I dont want to change it) but need to filter out the file extension. I see basename as being a very good option for doing so but cannot seem to get it to work.
Does anyone have a suggestion?

Here is the existing string:

Code
my %local_files; 
foreach my $file (</directorypath/fileprefix*>) { $local_files{basename($file)} = (stat($file))[7];
}


FishMonger
Veteran / Moderator

May 16, 2013, 11:52 AM

Post #2 of 3 (327 views)
Re: [StarkRavingCalm] Remove extensiton from existing string [In reply to] Can't Post

You can use a regex to strip out the extension or the File::Basename module.
http://search.cpan.org/~rjbs/perl-5.16.3/lib/File/Basename.pm


recruiter
User

May 16, 2013, 1:37 PM

Post #3 of 3 (318 views)
Re: [FishMonger] Remove extensiton from existing string [In reply to] Can't Post

A simple regex to remove the extension:


Code
$file =~ s/\.[^.]+$//;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives