Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check that a pattern DOES NOT contain a string

Status
Not open for further replies.

blues77

Programmer
Joined
Jun 11, 2002
Messages
230
Location
CA
Hello,

This is a rather stupid question but I'm no expert at Perl. I want to check to see if a file name contains the text '.mak' at the end of it's name and not '.mak.bak'. Currently my script searches all files that have the .mak extension as well as the .mak.bak extension. My code is

while ($file = readdir(MAKE))
{
if ($file =~ /.*\.mak$/)
{
open(FILE, $file) or die "Can't open the file $file: $!\n";
while ($line = <FILE>)
{ etc etc etc...

it opens not only the files with the .mak extension but also the files witht he .mak.bak extension. I figured that by putting the '$' at the end of the regular expression that this would take care of this problem, it hasn't. Any help is greatly appreciated.


Thanks
Mike
 
Mike,

Um, have you tried !~?

Code:
while ($file = readdir(MAKE))
{
    if ($file !~ /.*\.mak$/)
    {  etc etc etc

Hope this helps...

-- Lance
 
What does !~ do...essentially?
 
I have to say that I'm very surprised that [tt]if ($file =~ /.*\.mak$/)[/tt] didn't work. That should only match file names ending in &quot;.mak&quot;. (In fact, I just tested that locally and had no problem.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top