Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: $/ is playing havoc with my script.

by chester (Hermit)
on Sep 26, 2005 at 14:46 UTC ( #495125=note: print w/ replies, xml ) Need Help??


in reply to Re^3: $/ is playing havoc with my script.
in thread $/ is playing havoc with my script.

I think it's not so much a matter of "not knowing what you're doing", as wanting the regex engine to be consistent in that one symbol always means one thing.

If you use /ms all the time, then \A always means "beginning of the string", ^ means "beginning of a line", \z means "end of the string", $ means "end of a line, . means "any character", and [^\n] means "any character but a newline".

You lose no functionality, and you gain the benefit of consistency (and possibly intuitiveness, depending on your intuition). You also partially eliminate what the Apocalypse calls the "end-weight problem", which I assume means that you have no idea what your regex is doing until you scan all the way to the end to see the modifiers. Whether this is really a problem is debatable, and you still have i and g (etc.) to grapple with in any case.

Of course you also lose a bit of conciseness, which is a minus. It's just a question of style. TMTOWTDI


Comment on Re^4: $/ is playing havoc with my script.
Select or Download Code
Re^5: $/ is playing havoc with my script.
by sauoq (Abbot) on Sep 26, 2005 at 15:43 UTC
    You lose no functionality, and you gain the benefit of consistency (and possibly intuitiveness, depending on your intuition).

    Consistency isn't exactly a hallmark of Perl. (Take context as an example. Or the wide variety of behavior you get from builtins. Or the whole philosophy of TMTOWTDI.) The tradeoff it often makes is consistency for flexibility. Perl's flexibility makes it great! But, it pushes the burden of consistency off to us, the developers.

    And, it's partially in the interest of consistency that I would reject the advice to use /msx all the time because I expect that the great volume of Perl code written so far does not follow that advice. I'm also fairly certain that I'm not the only one who has seen [^\n] in someone's regex and suggested that using a lone dot would be more Perlish.

    The more practical reason, however, is that when I see /m or /s or \A or \Z these are strong visual cues that immediately indicate the data a given regex is dealing with probably has embedded newlines. I'd really rather not give that up.

    -sauoq
    "My two cents aren't worth a dime.";
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-08-30 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls