Hi Monks;

Today was a beautiful day watching the Solar eclipse on NASA TV. However, let me get to the point. I am trying to write a script that will check a file to see if the first 20 lines does not contain the word "DAVE". While searching for DAVE, I will like for the script to ignore case sensitivity i.e Dave and DAVE should be consider the same. If the first 20 lines of the file does not have dave, I will like to print the path of that file to a folder I called "input". I have used the find function to generate the paths to every files that I will love to search and store it in a file called "output". My problem is, I am not able to return the name of the file if it does not contain dave and i have not been able to make the search case insensitive.

Therefore, I am kindly asking any monk to help me. Thanks for your assistance.

use strict; use File::Find; my $count; my $path = "C:/hello/"; my $output = $path."Output.txt"; my $input = $path."Input.txt"; START: print ("Enter the name of your file >> "); chomp (my $name = <STDIN>); if(length($name)==0) { print (STDERR "\nYour did not respond!!\n"); goto START; } else { my $spath = $path.$name; open(FM, ">$output") && open(AM, ">$input") || die ("Cannot open, +$!\n"); find(\&search, "$spath"); close FM; open(SW, $output)||die ("Cannot open, $!\n"); while(<SW>) { my $flag = 1; chomp; if (open(ETA, $_)) { $count = 0; while(<ETA>) { foreach($_){$count++;}; if (($_ ne "Dave") && ($count <= 20)) { $flag = 0; } } if ($flag == 0) { #I am trying to print the name of the file containg "D +ave" in the first 20 lines print (AM "$_\n"); } } else { die ("Cannot open [$_], $!\n"); } }close AM; close SW; } sub search { if (((/\.c/)&&(!(/\.com/)))|(/\.h/)|(/\.pr/)) { print (FM "$File::Find::name\n"); } }

In reply to Finding names in files by gzayzay

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.