Solved

extract all after last period

Posted on 2009-03-31
5
228 Views
Last Modified: 2012-05-06
retrieve everything after the last period
test3.24.testing.233.txt
I'm in essence trying to retrieve the file extension
0
Comment
Question by:NewtonianB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24035830

my $s = "test3.24.testing.233.txt";
my ($ext) = $s =~ /\.([^.]*)$/;
 
print "$ext\n";

Open in new window

0
 

Author Comment

by:NewtonianB
ID: 24035883
great! what do the parenthesis signify, it doesn't work without them
0
 

Author Comment

by:NewtonianB
ID: 24035885
the parenthesis around $ext
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 250 total points
ID: 24035899
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

0
 

Author Closing Comment

by:NewtonianB
ID: 31565145
thanks!
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

737 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