Advertisement

08.16.2004 at 05:14AM PDT, ID: 21094992
[x]
Attachment Details

Ignore upper/lower case

Asked by bt707 in Perl Programming Language

Tags: upper, ignore, lower, case

i have a script that searchs some files and prints out the lines that contain both of two key words but i only get a print out when i have the case as it is in the file, sometimes these key words are in upper case and sometimes lower case, how can i tell the script to ignore the case.

#!/usr/bin/perl
use strict;

my @files =
(
     "mail.log_current",
     "mail.log_yesterday",
     "mail.log",
     "mail.log.0",
     "mail.log.1",
     "mail.log.2",
     "mail.log.3",
     "mail.log.4",
     "mail.log.5",
     "mail.log.6",
     "mail.log.7",
);

print "Enter first keyword: ";
my $word1 = <STDIN>; chomp $word1;
print "Enter second keyword: ";
my $word2 = <STDIN>; chomp $word2; #!!!!!
foreach my $file (@files) {
  next unless -f $file;
  open FILE, $file or die "Can not open $file $!\n";

  while (<FILE>) {
   print if (/$word1/ and /$word2/);
  }

  close FILE;
}


thanks,
Start Free Trial
[+][-]08.16.2004 at 05:47AM PDT, ID: 11809377

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: upper, ignore, lower, case
Sign Up Now!
Solution Provided By: leflon
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.16.2004 at 05:57AM PDT, ID: 11809483

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.16.2004 at 06:26AM PDT, ID: 11809785

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32