Re: When would you use qr// on a literal string?
- From: "it_says_BALLS_on_your forehead" <simon.chao@xxxxxxx>
- Date: 17 Jul 2006 08:47:37 -0700
Dr.Ruud wrote:
it_says_BALLS_on_your forehead schreef:
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? He claims that the use of the
qr// op here can help capture an error if the STRING is not a valid
regex. Does this make any sense?
I don't see any difference in using /+/ or qr/+/, both give the same
error.
My gut feeling says that split does a precompile on a /PATTERN/.
$ perl -MO=Deparse -e 'print split ".+"'
print split(/.+/, $_, 0);
$ perl -wle 'print split "+"'
Quantifier follows nothing in regex; marked by <-- HERE in m/+ <-- HERE
/ at -e line 1.
$ perl -wle 'print split /+/'
Quantifier follows nothing in regex; marked by <-- HERE in m/+ <-- HERE
/ at -e line 1.
$ perl -wle 'print split qr/+/'
Quantifier follows nothing in regex; marked by <-- HERE in m/+ <-- HERE
/ at -e line 1.
Great, that's informative. Thanks Doc.
.
- References:
- When would you use qr// on a literal string?
- From: it_says_BALLS_on_your forehead
- Re: When would you use qr// on a literal string?
- From: Dr.Ruud
- When would you use qr// on a literal string?
- Prev by Date: Re: why is perl -e 'unlink(glob("*"))' so much faster than rm ?
- Next by Date: Re: why is perl -e 'unlink(glob("*"))' so much faster than rm ?
- Previous by thread: Re: When would you use qr// on a literal string?
- Next by thread: Re: When would you use qr// on a literal string?
- Index(es):
Relevant Pages
|