Thanks, that was exctelly what I was after.
> In general, it a good idea to check your matching anyway, as in (don't
> need prefixing \s* if you're not capturing it):
I need the \s because the line can start with spaces but can't have anything else before. Thanks to your post I found that I also need to use '^' to ensure that the entire line only has the matching line
> dashes in char class can mean ranges, as in: > [0-9] or [a-z]
Thanks, it was indead the char '-' that I needed to match.
> by putting them in capturing parens, you could check to see which matched:
> if ( $line =~ /\s*([-\w_.]+):?\s+\*?([-\w_.]+)/ ) {
you mean $line =~ /\s*([-\w_.]+)(:?\s+\*?)([-\w_.]+)/ right?
I used your expression and it worked just like I wanted. I do need to check the middle value ($2) because it changes the meaning of $1 and $3.
Here is the entire function:
sub check_file {
my $fp = shift;
while(my $line = <$fp>) {
next if $line =~ /^\s*#/;
next if $line =~ /^\s*$/;
if($line =~ /^\s*!/) {
next if read_commands($fp, $line);
}
chomp($line);
if($line =~ /^\s*([\w\.\-]+)(:?\s+\*?)([\w\.\-]+)\s*$/) {
my ($a, $b, $c) = ($1, $2, $3);
# if $2 has a ':' then the file is in $1 else the file is in $3
if($b =~ /:/) {
print "Setting '$a'...\n" if -f $a;
$files{$a} = lc($c) if -f $a and $c;
} else {
print "Setting '$c'...\n" if -f $c;
$files{$c} = lc($a) if -f $c and $a;
}
}
}
}Thanks again for the help
Regards, Americo Albuquerque
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
