Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Apocalypse 5 and regexes (modifier reform)

by grinder (Bishop)
on Jun 06, 2002 at 09:43 UTC ( #172128=note: print w/replies, xml ) Need Help??


in reply to Apocalypse 5 and regexes

There's one thing that bugs me in the page on modifier reform, and that's the syntax for specifying when to match.

and I quote:

A modifier that starts with a number causes the pattern to match that many times. It may only be used outside the regex. It may not be bundled, because ordinals are distinguished from cardinals. That is, how it treats those multiple matches depends on the next character. If you say

s:3x /foo/bar/

then it changes the first 3 instances. But if you say

s:3rd /foo/bar/

it changes only the 3rd instance. You can say

s:1st /foo/bar/

I love the concept, but I'm not too keen on the use of 1st, 2nd, 3rd, 4th... I think it's just a bit too clever for its own good. Wearing my programmer's hat, I would rather see a more generic method. Here, 1, 2 and 3 are exceptions. It's not until 4 that the pattern repeats. Wearing my linguist's hat, at least for the only other language I feel qualified to speak for, French, the pattern is simpler: 1er, 2eme, 3eme... (accents and gender notwithstanding). So by some unit of measure, the chosen syntax is more difficult than it could be.

Knowing the shorthand for cardinals is not one of the simpler things foreign students learn about in English, thus non-English speakers are at more of a disadvantage than for other keywords such as die, split, rename... at least you can find those in a dictionary.

A more linguistically neutral approach would be to use n: 1n, 2n, 3n. It looks more mathematical and ties in with "to the nth degree" thereby retaining some notion of cardinality.

Ok, I admit this is a minor nit, but I did find it quite jarring when I read the Apocalypse.


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

Replies are listed 'Best First'.
Re: Re: Apocalypse 5 and regexes (modifier reform)
by TheDamian (Priest) on Jun 06, 2002 at 11:48 UTC
    This is a good point.

    Of course, I suspect we're not going to be snobs about the suffixes, and can simply suggest that ...th is the standard "skipping suffix" for anyone who can't handle all four. That is:

    s:1th/pattern/string/; s:2th/pattern/string/; s:3th/pattern/string/; s:4th/pattern/string/; # etc.

    would be perfectly valid.

    Alternatively, the rule might be that any suffix other than ...x means repetition:

    s:1um/pattern/string/; s:2ieme/pattern/string/; s:3itter/pattern/string/; s:4issimo/pattern/string/; # etc.
    ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-05-26 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (92 votes). Check out past polls.

    Notices?