lo*************@my-deja.com (lonelyplanet999) wrote in message news:<2c**************************@posting.google. com>...
Subject: Regular Expression Query
Poor subject line.
See http://www.cpan.org/authors/id/D/DM/DMR/subjects.post
# space between a +, - or " char b4 a keyword? remove it!
$in{keywords}=~s/ \+ +/ \+/g;
$in{keywords}=~s/ \- +/ \-/g;
$in{keywords}=~s/ \" +/ \"/g;
I would like to ask how the regexps function as the comment describe ?
They do not. The contstraint "before a keyword" is not in there.
Lets just look at one:
s/ \- +/ \-/g;
The backslashes are redundant, hyphen is not meta in string or regex.
s/search/relpace/g means replace as many non-overlapping matches for
the pattern /search/ with the string replace.
The pattern / - +/ matches a space, followed by a hyphen followed by
one or more spaces.
The string " -" is, err..., the string " -".
BTW the =~ binding operator is used to specify the variable on which
s/// is to act.
That's all there is to it.
No capturing, no interpolation, no subtlties. This really is about
the simplest s/// example you could imagine.
If you are at the stage where you have many questions at this level
then you probably are not at the stage where asking questions in
newsgroups is an effective use of your time or other people's. You
should probably be working through some basic Perl tutorials.
Actually, assuming this is someone else's code, it would appear that
the person who wrote it is not much further advanced. Anyone who had
even basic competance in Perl would usually combine these into a
single s///g
s/( [-+"]) +/$1/g;
As I said before attempting to learn Perl programming from this code
is not a good idea.
I have already pointed out to you that this newsgroup does not exist.
Really, it doesn't (it only appears to exist on misconfigured news
servers). For further explaination please see the FAQ. Please do not
start any more threads here.