Perl Code Question

Ed Eddington ed at pcr7.pcr.com
Tue Jan 11 09:53:34 CST 2000


Yes, '^' matches the begining of a string - but not in THIS context. It is 
some kind of "anything but" when used within the [] character list 
brackets. Like [a-z] matches any character from a thru z, [^a-z] matches 
anything but characters a-z. I gather it is supported from common regular 
expression syntax.

Ed

----------
From: 	Dave McKeon[SMTP:Mckeond at meijer.com]
Sent: 	Tuesday, January 11, 2000 10:37 AM
To: 	ed at pcr7.pcr.com
Subject: 	Re: Perl Code Question

Isn't that a forward/begin of string Anchor?

David McKeon
Meijer Server Architecture
Ext. 18841
Email:mckeond at meijer.com


>>> Ed Eddington <ed at pcr7.pcr.com> 01/11 10:28 AM >>>
This is bugging me. I know that this works, but don't know why. Below is an 
example search/replace that swaps the first 2 terms separated by a space.
The '^' here is performing some kind of "not" or "anything but" a space in
both of the [] terms. I have used this in code, but have never found this
usage of ^ in the Perl docs. Can someone explain what this '^' is doing?

s/([^ ]*) *([^ ]*)/$2 $1/;            # reverse 1st two fields




Thanks!
Ed









More information about the grand-rapids-pm-list mailing list