Jun 23, 2006, 2:57 AM
Post #2 of 2
I can see two problems here. One specific and one more general.
Re: [abhisri] filename matching
[In reply to]
The specific problem is with your syntax. Your filename check looks like this:
if( $flname = ~ /^$filename/ )
You've taken the =~ operator and split it into two. Perl interprets that as the = operator followed by the ~ operator. That's not what you want at all.
Incidently, if your match operator was working as you expected, it still wouldn't be going the right thing as your regex is checking for strings that start with $filename not strings that equal $filename. It's a subtle difference, but it might be important. Also for checking string equality, the equality operator (eq) is better than the match operator.
The more general problem is that you're doing far too much work for yourself. You've basically reinvented the glob. Why not use that instead.
Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks