http://www.perlmonks.org?node_id=81560


in reply to Re: Simple Question for you guys.
in thread converting carriage returns to <br> tags (was: Simple Question for you guys)

why are you using
s|[\r\n]|<br />|g;
instead of
s/[\r\n]/\<br \>/g;

are the pipes somehow more efficient in this case or just more readable?

the other thing i'm wondering about is the square brackets... does that mean  /[asdf\.]/ would search for each of those characters (a, s , d, f and Period) versus the string 'asdf.'

i know they're silly questions but i'm trying to get back up to speed with reading perl ... after about 8 months in visual basic for applications

there were so many REALLY nice things about working in VBA ... for example the editor will automatically fill display a list of the sub objects and methods of the object that you're working with... but then again the number of times i've struggled with the long way around a hash table or an array makes me really glad to be back in PerlScript (with a bit of Win32::OLE)

anyways ... i'm rambling :)

Replies are listed 'Best First'.
Re: Re: Re: Simple Question for you guys.
by voyager (Friar) on May 18, 2001 at 21:57 UTC
    You can choose your own delimiters. Anytime there's forward or back slashes in the reg exp, it' better to use a different delimitter. "Slanted toothpicks" or something is the name for the syndrome to avoid.
Re: Re: Re: Simple Question for you guys.
by AidanLee (Chaplain) on May 18, 2001 at 22:01 UTC

    pipes are no more efficient as regex delimiters. You have it exactly right on your latter guess though, it's a whole lot more readable than

    s/[\r\n]/<br \/>/g;

    You've also guessed right about the brackets. It's a way to specify a group of characters to match without specifying what order they appear in.