Re: When would you use qr// on a literal string?
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 17:31:50 +0200
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.
--
Affijn, Ruud
"Gewoon is een tijger."
.
- Follow-Ups:
- Re: 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?
- References:
- When would you use qr// on a literal string?
- From: it_says_BALLS_on_your forehead
- When would you use qr// on a literal string?
- Prev by Date: Re: CGI: Running a forked background process
- Next by Date: Re: When would you use qr// on a literal string?
- 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
|