please explain to me

please explain to me

am 02.02.2007 07:46:50 von robertchen117

please explain this to me:

s/\s+(!\W+)/$1 /;


s is replace, expecially (!\W+)

Re: please explain to me

am 02.02.2007 08:22:33 von Alex

robertchen117@gmail.com wrote:
> please explain this to me:
>=20
> s/\s+(!\W+)/$1 /;
>=20
>=20
> s is replace, expecially (!\W+)

perldoc perlre
It's an exclamation mark. AFAIK it doesn't have any special meanin, at
least in this context.

So the regexp replaces one or more whitespace characters followed by one
or more non-alphabetic characters beginning with (and including) an
exclamation mark.

For illustration, try using putting parenthesis around the captured
variable like so (dropping the last space):

perl -ane 's/\s+(!\W+)/($1)/;print'
input:
!"#&%asf
!/(%df
!"#¡è%asdf
#¡è%&asdf
output:
(!"#¡è%)asf
(!/(%)df
!"#¡è%asdf
#¡è%&asdf

Note the lack of a space on the third line, and the lack of an
exclamation mark on the fourth line. I guess the ! in the regexp might
have confused you into thinking it to be the NOT-operator?

HTH

--=20
Alex
e-mail: Domain is iki dot fi. Local-part is alext.
local-part at domain