[Melbourne-pm] nearly there...

Craig Sanders cas at taz.net.au
Wed Dec 19 21:44:42 PST 2007

On Thu, Dec 20, 2007 at 04:05:05PM +1100, Jacinta Richardson wrote:
> Craig Sanders wrote:
> > if it bothers you, then strip out the extras yourself:
> > 
> >          my $full_path = "$dirname/$entry";
> >          $full_path =~ s=//=/=g;

it's wrong (at least, sub-optimal), anyway.  should be:

$full_path =~ s=//+=/=g;

> Except, don't use = as your separator.  It breaks people's brains.  

only if they can't read perl.

i use = (when i don't use /) because it's one of the characters least
likely to appear as a character literal in a regexp also containing /
character literals. 

e.g. any regexp containing a literal / (which is why i'm using another
char as the separator, to avoid the unreadable ugliness of lots of \
escaping) is fairly likely to also have : characters ("http://.....")

'=' also has the significant advantage of being visually distinct from
most other characters (no highs or lows, just a horizontally centred
double-bar so it highlights the separation almost like whitespace). 

'-' works reasonably well too.

if the regexp has literal = characters too, i'll use something else.

the whole point is to make the regexp more readable.

> Use curly braces instead:

i find that ugly inside regexps, and don't/won't do it. curly braces are
for hashes or code blocks etc, not for uglifying regexps.

i'll use pretty nearly anything else before i'll use them.

> 	$full_path =~ s{//}{/}g;

the point of using a different separator is to make the regexp more
readable, not less.

YMMV, but to me, that is significantly less readable.


craig sanders <cas at taz.net.au>

Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
		-- Larry Wall in the perl man page

More information about the Melbourne-pm mailing list