Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks
i am littlebit knowledge in perl,at present i am working on task to parse log file to get starttime,endtime and
version,and also total time taken as stime-endtime, and it also counts the no of warning messages.
After getting this information ,the script should write these information in a text file.
.

Below is the code i am trying to parse the log file and also after running i am getting the lines which i am
attaching here below the title OUTPUT.

#!/usr/bin/perl -w open(F,"build.log") or die "can't open $!\n"; while($line=<F>) { chomp $line; @a=$line; foreach(@a) { #print "$_\n"; if($_=~/Building IVR Designer version /) { #print "$_\n"; push @b,$_; for(@b) { @c=split(" ",$_); print "@c\n"; #for(@c) # { # @m=split(" ",$_); # print "@m\n"; } } } } }

OUTPUT
Info: Wed Mar 28 18:53:03 2007:Building IVR Designer version 06.00.08....
Info: Wed Mar 28 18:53:03 2007:Building IVR Designer version 06.00.08....
Info: Wed Mar 28 18:56:31 2007:Building IVR Designer version 6.0 Completed !!!.

monks share yr ideas on this task and help me out towards the complition of this task
keep pouring your ideas....
  • Comment on how to extract fields from the output and how to convert it to html format
  • Download Code

Replies are listed 'Best First'.
Re: how to extract fields from the output and how to convert it to html format
by gloryhack (Deacon) on Apr 03, 2007 at 09:36 UTC
    If it's excusable that I point this out, we "keep pouring our ideas" but you keep coming back with elementary questions, which seems to indicate that our pouring is having little effect other than keeping you in a paycheck. At some point we want to see that your brain is thinking in Perl.

    Don't get me wrong. It's in our natures to offer assistance (or we'd not bother to reply in the first place), but at some point you have to start pouring your own ideas. Your question is elementary, and the solution obvious to any who has dedicated himself to learning his craft before selling it. Would you be comfortable going to a doctor who knows as much about his craft as you do about yours?

    That rant aside, you've not presented enough information for us to provide a workable solution. Among other things, you haven't explained what it is that distinguishes an error or warning message from an informational message, which is the most glaring omission from your query. This indicates that you haven't even thought through the question, let alone potential solutions to it. Ya gotta help us to help you!

    Have a happy day, but please spend at least part of it learning how to think your way through to solutions to your own problems.

Re: how to extract fields from the output and how to convert it to html format
by lima1 (Curate) on Apr 03, 2007 at 08:12 UTC
    Read perlre.
    #!/usr/bin/perl use strict; use warnings; #open my $F, '>', $file or die "can't open $!\n"; while (my $line = <DATA>) { chomp $line; my ( $date, $version ) = $line =~ m{ \A Info: \s (.*?):Building.*? version \s ([\d\.]+) }xms; + print "$date $version \n"; } __DATA__ Info: Wed Mar 28 18:53:03 2007:Building IVR Designer version 06.00.08. +... Info: Wed Mar 28 18:53:03 2007:Building IVR Designer version 06.00.08. +... Info: Wed Mar 28 18:56:31 2007:Building IVR Designer version 6.0 Compl +eted !!
    outputs:
    Wed Mar 28 18:53:03 2007 06.00.08.... Wed Mar 28 18:53:03 2007 06.00.08.... Wed Mar 28 18:56:31 2007 6.0
    The version is not correct, but it is because you truncated the output? If not: when you understand the regex, it should be easy to fix.
Re: how to extract fields from the output and how to convert it to html format
by Anonymous Monk on Apr 03, 2007 at 07:45 UTC