Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Return value from a binding operator?

by Don Coyote (Pilgrim)
on Apr 12, 2013 at 16:21 UTC ( #1028410=note: print w/replies, xml ) Need Help??

in reply to Return value from a binding operator?

Hi Chris,

Think of the middle match as a substition.

the match basically looks to match all of the string after the last / character. The end of line anchor $ is included in the capturing group, where we may be used to seeing this outside of the capturing group.

It does not so much as as strip the path off, rather matches the final part of the path, or the basename. I don't know if including the eol anchor $ retrieves the eol character or makes no difference.

m! #start match /? # 0 or 1 '/' ( # start capture $1 [^/] #consisting of no '/' characters + # 1 or more times $ # until and including eol (?) ) # end capture $1 ! # end match

this would also match a path with no directories.

Replies are listed 'Best First'.
Re^2: Return value from a binding operator?
by Spinone (Novice) on Apr 12, 2013 at 23:07 UTC

    Really useful, thanks.

    I'd worked out that /? meant "optional /" (though not why that was relevant) but, as an absolute Perl beginner, I had assumed that the caret slash (^/) meant "a line beginning with a slash" (still not sure why it doesn't), which didn't make any sense, so I obviously need to get to grips with that.

    Lots to learn....

      The ^ metacharacter has different meanings in different parts of a regex.

      Normally, it does mean "start of line", as you thought. If the regex were m!^/!, then it would match lines beginning with /.

      However, as the first character in a character class, it negates the class, so [^/] means "match any character except /". (But, again, that's only if it's the first character in the class - [/^] means "match either a / or a ^". And [^/^] would match any character except those two.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028410]
[marinersk]: LanX, the problem is that the lack of interface visual stability is disconcerting to me. The Nodelet appearing and disappearing is distracting, and despite over a decade, still troubles me. It jangles me.
[LanX]: I see
[marinersk]: I appear to be unusually dependent on spacial stability. I have had trouble from someone moving an object a mere four inches to the left.
[Eily]: I think the solution is to write posts so brilliant that you gain XP on each refresh, no matter how often :P
[marinersk]: Eily++ and LOL
[marinersk]: I get a lighter version of this disconcertion (new word?) when the n points remaining until rank disappears.
[choroba]: :-D

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-05-29 13:57 GMT
Find Nodes?
    Voting Booth?