Perl Code Question

Doug Kyle dkyle at grpl.org
Tue Jan 11 10:55:39 CST 2000


You've correctly answered your own question - a caret in front of a list in
square brackets matches non-members of that list.  What I don't see is why the
* before the second ()s?  Also, using + inside the ()s would prevent 'zero or
more matching' happening if a line begins with spaces, in which case the
example would not work.

I don't know about where it's supported from..

--
Doug Kyle - Information Systems
Grand Rapids Public Library
"Try to imagine all life as you know it stopping instantaneously and every
molecule in your body exploding at the speed of light." - Dr. Egon Spengler


Ed Eddington wrote:

> 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