extract all after last period

Posted on 2009-03-31
Last Modified: 2012-05-06
retrieve everything after the last period
I'm in essence trying to retrieve the file extension
Question by:NewtonianB
  • 3
  • 2
LVL 40

Expert Comment

Comment Utility

my $s = "test3.24.testing.233.txt";

my ($ext) = $s =~ /\.([^.]*)$/;

print "$ext\n";

Open in new window


Author Comment

Comment Utility
great! what do the parenthesis signify, it doesn't work without them

Author Comment

Comment Utility
the parenthesis around $ext
LVL 40

Accepted Solution

mrjoltcola earned 250 total points
Comment Utility
The regex match operator =~ returns a matches in a list context.

my ($v1, $v2, $v3)   is a list
my $v1, $v2, $v3 is not a list, it is 3 scalars.

You can rewrite the whole thing if you want to:

if($s =~ /\.([^.]*)$/) {

   my $ext = $1;


Open in new window


Author Closing Comment

Comment Utility

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MySQL Web Database 5 105
hard perl script 16 144
Edit Odbc.ini using perl module 2 69
Perl File::Find alternative 1 23
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now