[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

extract all after last period

retrieve everything after the last period
test3.24.testing.233.txt
I'm in essence trying to retrieve the file extension
0
NewtonianB
Asked:
NewtonianB
  • 3
  • 2
1 Solution
 
mrjoltcolaCommented:

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

Open in new window

0
 
NewtonianBAuthor Commented:
great! what do the parenthesis signify, it doesn't work without them
0
 
NewtonianBAuthor Commented:
the parenthesis around $ext
0
 
mrjoltcolaCommented:
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
 
NewtonianBAuthor Commented:
thanks!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now