Solved

extract all after last period

Posted on 2009-03-31
5
214 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
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with bash and/or perl commands on OS X Terminal 9 104
Perl efficient DB Call 8 87
File Find regex problem 4 62
Export Variables in Perl 3 68
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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