RE: grep question

2006-01-17 Thread Charles K. Clarkson
Spencer_Lists <> wrote:

: my @files = <$path/*>;
: my $file_exists = 1 if (grep/$newname/,@files);

Have you tried using \Q to escape the special
characters in $newname?

 my $file_exists = 1 if grep /\Q$newname\E/o, @files;


As an alternative you could stop using a regular
expression for the match (untested code).

 my $file_exists = 1 if grep $_ eq $newname, @files;


And if you need multiple tests, you could use a hash
(untested code).

 my %file_exists;
 @file_exists{ @files } = (1) x @files;

 if ( $file_exist{ $newname } ) {
 # do something
 }




HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Yet another regex question

2006-01-17 Thread Thomas, Mark - BLS CTR
> I'd like to thank everybody who came up with suggestions.  
> One thing I 
> forgot to point out is that there are also people with 
> whitespace in their 
> *given* names, which seems to make things even more problematic 

I've updated my solution to accommodate that:

while () {
my @cols =
m/^(\d+)  #id1
  \s(\(\d+\)) #id2
  \s([\w ]+), #lastnames
  \s([^\d]+)  #first name
  \s([\d\.]+) #data1
  \s([\d\.]+) #data2
  \s([\d\.]+) #data3
  \s([\d\.]+) #data4
  \s(\w+) #country code
  \s([\d\.]+) #data5
/x;
printf "%s\n", join "\t", @cols;

}

__DATA__
1 (1) DAVENPORT, LINDSAY 3380.00 16 .00 49.00 USA .00
2 (2) CLIJSTERS, KIM 3206.00 17 .00 .00 BEL .00
28 (28) MOLIK, ALICIA 671.00 15 .00 195.00 AUS .00
29 (33) MEDINA GARRIGUES, ANABEL 660.75 27 30.00 10.00 ESP 2.00
30 (35) KOUKALOVA, KLARA 660.75 23 16.00 20.00 CZE 2.00
77 (84) MONTOYA, INIGO CONQUISTADOR 100.22 23 16.00 20.00 ESP 2.00


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs