Perl Code Question

Dave McKeon Mckeond at meijer.com
Tue Jan 11 12:03:49 CST 2000


After looking at the string a bit more I'm fairly certain its a hold out from perl 3 or perhaps earlier.  

s/(\S*) *(\S*)/$2 $1/

Is quite a bit easier to read and accomplishes I believe the same thing.   I haven't tested it, but \S is not whitespace so it should work depending on how your formating the string that is. 

If it crashes at fails, I blame it all on this bottle of Nyquil I've been cuddling. :)



> -----Original Message-----
> From: owner-grand-rapids-pm-list at pm.org 
> [mailto:owner-grand-rapids-pm-list at pm.org]On Behalf Of Ed Eddington
> Sent: Tuesday, January 11, 2000 10:29 AM
> To: 'grand-rapids-pm-list at happyfunball.pm.org' 
> Subject: Perl Code Question
>
>
> 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
>
>



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






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