Re: When would you use qr// on a literal string?



it_says_BALLS_on_your forehead <simon.chao@xxxxxxx> wrote:
I thought that qr was mainly used for pre-compiling variables into
regex patterns, but a colleague uses it like so:

my ( $name, $value ) = split qr/=/, $string;

Are there any benefits to doing this?


Not that I can see.


He claims that the use of the
qr// op here can help capture an error if the STRING is not a valid
regex.


I have no idea what "capture an error" might mean...


Does this make any sense?


No, unless he can give an example where using qr// gives more
info than an m// with the same pattern.

These both make the same output for instance.

perl -e 'qr/(/'

and

perl -e 'm/(/'

Can your colleague provide a counter-example that shows qr// as
somehow "better"?


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.



Relevant Pages