Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Validation of unix permissions

by eibwen (Friar)
on May 08, 2005 at 05:35 UTC ( [id://454970]=note: print w/replies, xml ) Need Help??


in reply to Validation of unix permissions

I want to match a comma-separated string, with zero or more items, and each item matches a particular regexp,

I presume you're trying to parse valid chmod input such as ug=rwx,o=rx. While your statement allows for a number of alternative permutations, this seems the most likely.

With regard to Update 2 in the OP and given the above understanding of valid input, I believe you may be looking for something akin to:

foreach (split /,/, $perm) { warn "Invalid permission setting: $_" unless /^[ugoa]+=[rwxsS]+$/; }

However, while this is significantly more informative, it doesn't adhere to the spirit of the OP prescription:

The idea is that I'm trying to take a single regexp, and have it match multiple times with an optional separator.

If you just want to detect whether the string contains an invalid permission and you don't need to inform the user of the errant setting, it is possible to use a single regex:

foreach (@perms) { warn "Invalid permission setting detected in $_" unless /^(([u +goa]+=[rwxsS]+)(?(?!$),))+$/; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://454970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found