• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Comparing Strings

Why wont this compare correctly, all the log file names are in the array and they display fine, but the compare is not evaluating correctly.....It executes the if statement everytime, when it should only do it if the current log file name does not match one of the 3 in the statement.

##########################################################
#gets the log file names and chops off the beggining paths
##########################################################
sub getLogNames {
    #This puts every file in the $logPath directory in the array @logFileNames
    @logFileNames = <$logPath*>;

    #Iterates through the filenames and chops the pathname off the file
     $index = 0;
     foreach $x (@logFileNames){
         #Does the chopping off of the pathname
       $x =~ s#.*/##;
       $logFileNames[$index] = $x;
       chomp $x;
       if (($x ne 'albd_log') || ($x ne 'db_server_log') || ($x ne 'view_log')){
           print "$x \n";
           $logFileNames[$index] = "";
       }
         $index ++;
     }
    print "CONTAINS ======> @logFileNames \n";

}
0
Pheonix911
Asked:
Pheonix911
  • 4
1 Solution
 
manav_mathurCommented:
Shouldnt the || be replaced with &&

Manav
0
 
manav_mathurCommented:
if your filename is albd_log, first if condition evaluates false but second and third evaluate true. hence, in case of ||, the entire expression is true.

Infact, the entire expression will never be false because a file cannot have 3 names.

<amab
0
 
Pheonix911Author Commented:
Im feeling a little slow today, cant belive I didnt catch that....thanx for the help
0
 
manav_mathurCommented:
happens everytime....:-)

Manav
0
 
manav_mathurCommented:
But why  a B?? Is there anything else that I didnt elaborate on??

Manav
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now