[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] requesting quick help



[Hmmm... Weird. Cox didn't forward this to the pm.org server? Let's try again using my smtp server so I can debug...]


From: Jay Hannah <jay@jays.net>
Date: January 10, 2007 9:11:30 PM CST
To: kiran bina <kiranbina@gmail.com>
Cc: Nebraska USA Perl Mongers of Omaha <omaha-pm@pm.org>
Subject: Re: requesting quick help

(1) You've got a "sleep 1" on line 44 slowing you down. :)

(2) Given your filename list

Org1_Org2.common
Org1-Org2-Org3.A_unique
Org1_Org2_Org3.common
Org1_Org3.common
Org2-Org1-Org3.B_unique
Org2_Org3.common
Org3-Org1-Org2.C_unique

In this block of code

if($fileName =~ /\.BC98/ || $fileName =~ /\.BC90/ || $fileName =~ /B_Unique/ || $fileName =~ /Org2_Org3.common/ || $fileName =~ /Org2- Org1-Org3.B_unique/)
    {
        print " 1 Searching file: $file_names[0]";
       @file_names = ($file_names[0]); # ATC
    }
elsif($fileName =~ /C_Unique/ || $fileName =~ /Org3-Org1- Org2.C_unique/)
    {
        print "2 Searching file: $file_names[1]";
       @file_names = ($file_names[1]); # SE_Org3
    }
elsif($fileName =~ /ABC/ || $fileName =~ /AB/ || $fileName =~ / AC98/ || $fileName =~ /AC90/ || $fileName =~ /A_Unique/ || $fileName =~ /Org1-Org2- Org3.A_unique/ || $fileName =~ /Org1_Org2.common/ || $fileName =~ /Org1_Org2_Org3.common/ || $fileName =~ / Org1_Org3.common/)
    {
        print "3 Searching file: $file_names[2]";
       @file_names = ($file_names[2]); # RP62A
    }
    print "$fileName => $file_names[0]\n";

you were probably expecting the file "Org1_Org2_Org3.common" to fall into the "3 Searching file" block, but it doesn't because you're catching that filename with your

   $fileName =~ /Org2_Org3.common/

regex up in the "1 Searching file" block. That's because "Org1_Org2_Org3.common" does indeed contain the string "Org2_Org3.common", which is the question your regex asks Perl to answer.

You don't need regexs to do what you're doing, so you're less likely to get stung by just avoiding them like so:

if($fileName eq "Org2_Org3.common" || $fileName eq "Org2-Org1- Org3.B_unique")
    {
        print "1 Searching file: $file_names[0]";
       @file_names = ($file_names[0]); # ATC
    }
    elsif($fileName eq "Org3-Org1-Org2.C_unique")
    {
        print "2 Searching file: $file_names[1]";
       @file_names = ($file_names[1]); # SE_Org3
    }
elsif($fileName eq "Org1-Org2-Org3.A_unique" || $fileName eq "Org1_Org2.common" || $fileName eq "Org1_Org2_Org3.common" || $fileName eq "Org1_Org3.common")
    {
        print "3 Searching file: $file_names[2]";
       @file_names = ($file_names[2]); # RP62A
    }
    print "$fileName => $file_names[0]\n";

... or something even tighter... :)

Looks like that produces the output you were expecting?

HTH,

j