Beware wrote:
Hi all,

Hello,

i've a question on my perl script.

In my script i read a file line per line, and check if keywords are in
uppercase. To do that, i've an array filled with all used keywords.

On each line, i check all keywords with a foreach loop.

Well, this is my code :


my $lines = 0;

You don't really need this variable, just use the built-in $. variable.


while (<SOURCE>  )
{
    # cut '\n'
    chomp($_);

    #List of keywords
    my @keywords = ("all", "wait", "for");

You don't really need this variable inside the while loop.


    #Check all keyword
    foreach $item (@keywords)
    {
       # keywords detected
       if ( /$item\b/i and !/\s*--/)

You should probably have anchors at the beginning as well as the end:

       if ( /\b$item\b/i && !/\s*--/ )


       {
          # remove keywords already in uppercase
          my $temp = $_;
          my $item_maj = uc($item);
          $temp =~ s/$item_maj//g;

No need for the $item_maj variable and you should use the anchors here as well:

          $temp =~ s/\b\U$item\E\b//g;


          # check if  any keywords
          if ( $temp =~ /$item\b/i )
          {
             print "keywords is lowercase line : ".$lines."\n";
             last;
          }
       }
    }
    $lines++;
}
close ( SOURCE );



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to