Hi Asad,

some comments on your script:

On Wed, 8 May 2013 11:34:14 +0530
Asad <asad.hasan2...@gmail.com> wrote:

> Hi All ,
> 
>           Thanks to you all for the inputs . I have created the following
> script :
> 
> use warnings;
> use strict;
> use File::Slurp qw(read_file);
> use constant LIMIT => 3;    ## Number of lines wanted
> use constant UPPERLIMIT => 9;
> 
> open (OUTFILE, '>','d:\perl\OUTPUT.TXT');

1. Don't use bareword filehandles - use lexical ones instead.

2. Use autodie, or the "or die" thing:

http://perl-begin.org/tutorials/bad-elements/#open-function-style

> 
> #my $file = $ARGV[0];
> 
> my $filename = 'LOGFILE';
> 
> open(FH, '<', $filename) or die $!;

1. Don't use bareword filehandles.

2. Including a meaningful message in the "die $!".

> 
> my @lines = read_file($filename);
> 
> for ( 0 .. $#lines ) {

Don't iterate using $_:

http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore

Use an explicit, lexical, iteration variable.

In recent perls, you can also use keys(@lines).

>     if ( $lines[$_] =~ m{\b(VERIFICATION_FAILED)\b}i ) {

Use «(?: ... )» (for clustering) instead of «( ... )» (for capturing and in
this case, it is completely not-needed.

>      print "$_\n";
>          print $lines[$_];
>        print OUTFILE join " " => '*', @lines[ $_ - LIMIT .. $_ + UPPERLIMIT
> ], $/;

MAke sure the upper and lower limits to the range are bounded.

>     }
> elsif ($lines[$_] =~ m{\bfatal\b}i)
> {
>         print OUTFILE join " " => '*', @lines[ $_ - LIMIT .. $_ +
> UPPERLIMIT ], $/;
> }
> elsif ($lines[$_] =~ m{\b'Exception Severity: 1'\b})
> {
>         print OUTFILE join " " => '*', @lines[ $_ - LIMIT .. $_ +
> UPPERLIMIT ], $/;
> }
> elsif ($lines[$_] =~ m{\bstop\b}i)
> {
>         print OUTFILE join " " => '*', @lines[ $_ - LIMIT .. $_ +
> UPPERLIMIT ], $/;
> }

1. You're using « $lines[$_] » too much - you should assign it to a variable.

2. There's a lot of duplicate code in the «print OUTFILE join " " => '*',
@lines[ $_ - LIMIT .. $_ + UPPERLIMIT ], $/;»

> elsif ($lines[$_] =~ m{\bfail\b}i)
> {
>         print OUTFILE join " " => '*', @lines[ $_ - LIMIT .. $_ +
> UPPERLIMIT ], $/;
> }
> else
> {
> print " No Errors found \n";
> }
> 
> Please review if the above code seems ok .

Hope it helped.

> 
> Also want to know how to get this to UI(html page) interface for example a
> html page which has a browse button to select the log file and it displays
> the output parsing through the logic any module which this does or what you
> suggest.

You should write a module for that, and then use Dancer or whatever. See:

1. http://perl-begin.org/topics/modules-and-packages/

2. http://perl-begin.org/uses/web/

> 
> Any pointers for UI interface or any book I can refer would be helpful.
> 

The books are likely going to be out-of-date.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
First stop for Perl beginners - http://perl-begin.org/

Jack: Hi Sophie!
Sophie: Don’t “Hi, Sophie!” me.
Jack: Don’t “Don’t ‘Hi, Sophie!’ me” me!

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
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