in reply to Whats your favorite nonstandard regex quote char?
I almost universally use s[...][...]g; for regexes the exception being when I'm using the /e modifier in which case I tend to use s[...]{....}ge; as the curlies give a visual indication that the right-hand side is active rather than passive. In this specific case, the same regex in my test code is coded as
s[[{].*?[}]][{$sub[$n++]}]g;
which (I think) looks fine under the syntax highlighting in my editor, but looked altogether too confusing when rendered in the b&w of the preview page. So I looked for some way of rendering it more clearly in this environment. I tried various options and settled on
s_\{.*?\}_{$sub[$n++]}_g;
as the least bad.
As you pointed out, perl is very clever about deciding whether a metachar is or is not being used as a metachar, but I still tend to escape them as my brain/eyes are less adept at the art.
I've recently started using [metachar] (unashamedly stolen from some of Abigail-II's posts) instead of \metachar for escaping metachars in regexes as it allows me to use a consistant method for single and multiple alternatives, and I'm finding that consistancy is the key to easy visual parsing of code.
I use m[...] almost universally in preference to /.../, and map{...}; grep{...}; even when the blocking isn't strictly required for similar reasons. I find the visual consistancy and ease of extensibility far outway the minor performance penalty.
I've never yet posted a set of personal style rules as I'm still formulating mine. Very little of my style (or lack thereof) is yet fixed in stone, I tend to see things that other people are doing that seem particularly clear/neat/concise/cool and try them for a while and see what sticks. Those that don't bug me to type, hinder my reading or cause any problems in other ways tend to stay.
There are some which I use in my own code that I relegiously remove from the code when posting. Eg.
.... #! This is a comment
Try as hard as I might to tailor my syntax highlighter definition, it still confuses everything on a line after
$#array
with a comment and highlight it accordingly. So I changed the comment card spec to being #!. This means that all the comments and the shebang lines are displayed in a muted green, which suits me. However, I started removing (mostly) the ! from the comments when posting as a private msg from someone said that everytime he looked at the code I posted with them in, he saw multiple shebag lines and freaked.
I guess I should get around to setting up PerlTidy to filter code to my preferences on input and back to something "more normal" on output, but that probably wouldn't help much as I tend to c&p directly from the editor. I also have a set of macros that do most of the transformations--tab width, curly positioning etc--already in my editor. To use perltidy I would have to save the code out to a file, load it in another editor to view it in the "more normal" form a c&p from there, which would just be a pain.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Whats your favorite nonstandard regex quote char?
by kelan (Deacon) on Apr 23, 2003 at 15:05 UTC |