[tpm] New Regex question

Chris Jones cj at enersave.ca
Sat Oct 27 15:19:10 PDT 2012


Thank Stuart, I did end up using $File::Find::dir, very helpful.

New question.  I would like to replace multiple spaces with single 
spaces and multiple end of line  with a single end of line.

I thought this might work:
$expression =~ s/(\s+)/\1/g; # puts back what it found

So I tried
$expression =~ s/(\s)/\1\s/g;
That gave me the original double white space plus an s.

Any insight very much appreciated.


But that replaces all white spaces with
At 07:55 PM 23/10/2012, Stuart Watt wrote:
>On 2012-10-23, at 2:32 PM, Chris Jones <cj at enersave.ca> wrote:
>
> > My tests are working correctly, I don't try to delete directories.
> >
> > My follow on question is how do you tell File:Find to skip the 
> directory the script is called from.  I only want to delete files 
> in the sub-directories.
> >
> > I can test each file to see if it's directory is '.' but would 
> seem somewhat inefficient?
>
>String matching efficiency is probably a thousand times higher than 
>file system accesses, so if I was you I really wouldn't worry about 
>it. I tend to use no_chdir => 1 and $File::Find::name, but to skip 
>everything in the base directory, probably checking to see if 
>$File::Find::dir is the same as the base should be quick and effective.
>
>All the best
>Stuart
>_______________________________________________

 >>
Christopher Jones, P.Eng.
Suite 1801, 1 Yonge Street
Toronto, ON M5E1W7
Tel. 416-203-7465
Fax. 416-946-1005
email cj at enersave.ca



More information about the toronto-pm mailing list