Home: Perl Programming Help: Beginner:
A confusing set of character



boonflies
New User

Apr 23, 2017, 9:44 PM


Views: 1324
A confusing set of character

I am trying to understand perl with a working program. I got stuck at place where I found,

elsif (/\.?(?:.*\.)+(.*)/)

can that be broken down to understand?


Laurent_R
Veteran / Moderator

Apr 23, 2017, 11:20 PM


Views: 1322
Re: [boonflies] A confusing set of character

It is called a regular expression and it is trying to match$_ to the pattern. This looking into $_ for:

Code
/     start of regex 
\.? zero or one literal dot
(?:.*\.)+ a group occurring one of more time (see below)
(.*) a capture group capturing any number
of any characters until the end of the line
/ end of regex

The first group consists of: any number of any characters (except new line) followed by a literal dot.

Overall, this seems to be looking for file and directory names and trying to capture the extension.