Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   simple help (http://www.velocityreviews.com/forums/t891487-simple-help.html)

jaw56856@yahoo.com 03-22-2005 10:24 PM

simple help
 
OK this should be simple, but....
I am parsing an error file greping for a cretin conditions, this part I
have working fine
While(<error_file>)
{
if (/...what ever it is I am looking for.../)
print output $_
}
That is working fine.
I then log the last runtime (from the error file line item time stamp),
and this too works fine
So the next time I can pick up where we left off and not revisit the
same errors
$last_runtime = $logfile[$#logfile];

What I would like to do is search the error_file from the $last_runtime
on
But I just can't get the strings to match!
What I was trying is this
$x = 1;
while (<error_file > ){
if ($x)
{
$comp_string = substr($_, 0, 20);
if(($last_runtime eq $comp_string) )
{ $x = 0;print ("this is where i left off\n")}
print ($comp_string, "\n");
}
else
{
print (" found the starting point\n");
if (/...what ever it is I am looking for.../)
{
print $_;
print ("error found");
}
}
so what is wrong with the if(($last_runtime eq $comp_string) )
statement???
It never matches??


Tad McClellan 03-22-2005 11:32 PM

Re: simple help
 
jaw56856@yahoo.com <jaw56856@yahoo.com> wrote:

> Subject: simple help



Please put the subject of your article in the Subject of your article.

That is what it is there for.


> I am parsing an error file greping for a cretin conditions,

^^^^^^
^^^^^^

Excluding all of the smart conditions? :-)


> have working fine
> While(<error_file>)



I don't believe you, as that is not Perl code. Case matters.


> print output $_


> That is working fine.



It will stop working fine when you upgrade perl and it introduces
a new function named output().

You should use UPPER CASE for filehandles.



> so what is wrong with the if(($last_runtime eq $comp_string) )
> statement???
> It never matches??



I dunno, did you print out the two values?

print "\$last_runtime is '$last_runtime'\n";
print "\$comp_string is '$comp_string'\n";


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

jaw56856@yahoo.com 03-23-2005 02:28 PM

Re: simple help
 
it was while in the code(as seen in the snipit below), i was a typo. I
have placed print statements to make sure i was matching, was one of
the first steps in debuging the problem.
I have tried pulling a shorter sting to see if i was picing up some
other char, but nothing. It has been 5 yrs since i played with perl.
So i am assuming that this something simple that i am over looking. eq
is the correct string operator. So why would it not catch?


Arndt Jonasson 03-23-2005 03:55 PM

Re: simple help
 

jaw56856@yahoo.com writes:
> it was while in the code(as seen in the snipit below), i was a typo. I
> have placed print statements to make sure i was matching, was one of
> the first steps in debuging the problem.


"Snipit below"? There was no snipit or snippet in your article.

jaw56856@yahoo.com 03-23-2005 04:22 PM

Re: simple help
 
What I was trying is this
$x = 1;
while (<error_file > ){
if ($x)
{
$comp_string = substr($_, 0, 20);
if(($last_runtime eq $comp_string) )
{ $x = 0;print ("this is where i left off\n")}
print ($comp_string, "\n");


}


else
{
print (" found the starting point\n");
if (/...what ever it is I am looking for.../)
{
print $_;
print ("error found");
}

}


Tad McClellan 03-23-2005 05:21 PM

Re: simple help
 
jaw56856@yahoo.com <jaw56856@yahoo.com> wrote:


Please post some context when composing a followup.

Have you seen the Posting Guidelines that are posted here frequently?


> What I was trying is this


[snip code]

Post a short and complete program *that we can run*, and we will
surely be able to solve your problem.

We cannot duplicate your problem because you did not supply
the data (file contents) that you are processing.

If you need file contents in your code, then include it as
a __DATA__ section, as described in the Posting Guidelines.


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

jaw56856@yahoo.com 03-25-2005 03:30 PM

Re: simple help
 
Tad, I had not seen the Posting Guidelines, but have now. Here is the
script that is trying to parse the log file. if i were to just run the
string matching section it work, but when i try and the logic to pick
up where i left off, it never matches.

here is the script
open (test, "TradingManager_ckt49_h.log") || die "no data to check";
open (logfile, "logfile.txt") || die " no log file";
open (errorfile, ">>errorfile.txt") || die " no error file";

@logfile = <logfile>;
$last_runtime = $logfile[$#logfile];

print $last_runtime;

$x = 1;
while (<test> ){
if ($x)
{
$comp_string = substr($_, 0, 20);
if(($last_runtime eq $comp_string) )
{ $x = 0;print ("whooooo\n")}
print ($comp_string, "\n");

}
else
{
#print (" found the starting point\n");
if (/ERROR.*Msg: 249/){
print $_;
#print ("we are here");
print errorfile $_;
}
}
$max_runtime = substr($_, 0, 20);

}
print $max_runtime
open (logfile, ">>logfile.txt") || die " no log file";
print logfile $max_runtime, "\n";
close (test);
close (logfile);
close (errorfile);

_DATA_ <<TradingManager_ckt49_h.log>>
24 Feb 2005 13:01:11 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:02:21 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:03:21 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:04:21 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:05:28 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:06:36 WARNING - <executing script ***
24 Feb 2005 13:07:36 WARNING - <executing script ***

24 Feb 2005 13:09:36 WARNING - <executing script ***
24 Feb 2005 13:10:36 WARNING - <executing script ***
24 Feb 2005 13:11:36 WARNING - <executing script ***
24 Feb 2005 13:12:54 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:13:55 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:14:12 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:15:12 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:16:45 ERROR - <gmem_table_sort.c, line #8088>:
TABLE_PivotInternal(): ***
24 Feb 2006 16:15:58 ERROR - <prc_gui.c, line #2503>: ***
25 Feb 2006 09:17:36 ERROR - <db_api_ct.c, line #2120>: ***
21 Feb 2005 13:56:59 ERROR - <db_api_ct.c, line #241>: *** Msg: 249,
***
21 Feb 2005 13:56:59 ERROR - <db_api_ct.c, line #241>: *** Msg: 248,
***
24 Feb 2006 13:27:45 ERROR - <gmem_table_sort.c, line #8110>:
TABLE_PivotInternal(): ***
21 Feb 2005 13:56:59 ERROR - <db_api_ct.c, line #241>: *** Msg: 249,
***
24 Feb 2006 13:27:46 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2006 16:15:56 ERROR - <prc_pv.c, line #1309>: ***

_DATA_<<logfile.txt>>
25 Feb 2005 09:17:35
25 Feb 2005 09:17:36
25 Feb 2005 09:17:37
25 Feb 2005 09:17:38
25 Feb 2005 09:17:39
25 Feb 2005 09:17:40
25 Feb 2005 09:17:41
25 Feb 2005 09:17:42
25 Feb 2005 09:17:43
25 Feb 2005 09:17:44
25 Feb 2005 09:17:45
25 Feb 2005 09:17:46
25 Feb 2005 09:17:47
25 Feb 2005 09:17:48
25 Feb 2005 09:17:49
25 Feb 2005 09:17:50
25 Feb 2005 09:17:51
25 Feb 2005 09:17:52
25 Feb 2005 09:17:53
25 Feb 2005 09:18:36
24 Feb 2006 13:27:45
24 Feb 2006 16:15:58
24 Feb 2006 16:15:58
24 Feb 2006 16:15:56
24 Feb 2006 16:15:56
24 Feb 2005 13:09:36


Paul Lalli 03-25-2005 04:17 PM

Re: simple help
 
jaw56856@yahoo.com wrote:
> Tad, I had not seen the Posting Guidelines, but have now.


But you decided either to not read them, or not to follow them?

You are still not quoting any context in your follow up.

You still have not created a short-but-complete program, using __DATA__
sections (which is not the same as simply including the data in your
program and telling us to put it in a file with a specific name).

Paul Lalli

Tad McClellan 03-25-2005 05:15 PM

Re: simple help
 
jaw56856@yahoo.com <jaw56856@yahoo.com> wrote:

> Tad,



Please post some context when composing a followup.

I've asked you to do this before, why have you chosen to not do that?


> I had not seen the Posting Guidelines, but have now.



My implication was that you would *follow* at least some of
the points made there.

I shrugged it off earlier figuring that you just didn't know
about them, but now you are coming off as a very self-centered
and rude person.


> Here is the
> script


> here is the script



But it is not a short and complete program *that we can run*.

I've asked you to do this before, why have you chosen to not do that?

The Posting Guidelines suggest it too, why have you chosen to not
follow the suggestion?


> open (test, "TradingManager_ckt49_h.log") || die "no data to check";
> open (logfile, "logfile.txt") || die " no log file";
> open (errorfile, ">>errorfile.txt") || die " no error file";



You should use UPPER CASE for filehandles.

I've asked you to do this before, why have you chosen to not do that?

You should include the $! variable in the die message so that
you will know *why* it failed.


> @logfile = <logfile>;



Every line in the array has a newline at the end.


> $last_runtime = $logfile[$#logfile];



$last_runtime = $logfile[-1];

That has a newline at then end too then.


> print $last_runtime;



Didn't you see a newline when you print()ed this?

I suggested this before

print "\$last_runtime is '$last_runtime'\n";

so that you could see what is being compared, why have you
chosen to not do that?


> $comp_string = substr($_, 0, 20);



Is the 20th character from $_ a newline?


> if(($last_runtime eq $comp_string) )


> print ($comp_string, "\n");



I suggested this before

print "\$comp_string is '$comp_string'\n";

so that you could see what is being compared, why have you
chosen to not do that?


> _DATA_ <<TradingManager_ckt49_h.log>>



I've asked you to use a __DATA__ section before, why have you
chosen to not do that?


I am "talking to the hand" here.

You are on your own.

*plonk*


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

lynn 03-25-2005 07:55 PM

Re: simple help
 

<jaw56856@yahoo.com> wrote in message
news:1111764617.385242.33250@o13g2000cwo.googlegro ups.com...
> Tad, I had not seen the Posting Guidelines, but have now. Here is the
> script that is trying to parse the log file. if i were to just run the
> string matching section it work, but when i try and the logic to pick
> up where i left off, it never matches.
>

(script snipped)

You really need to follow the guidelines that Tad suggested.
You need to make it easy for someone to help you. If I
had asked this question I would have provided a script
that can be run by anyone. (See end of post for example)

Now that, that is done, what is the problem that you are trying to solve?


use strict;
use warnings;
use diagnostics;

my @logfile = qw(
25 Feb 2005 09:17:35
25 Feb 2005 09:17:36
25 Feb 2005 09:17:37
25 Feb 2005 09:17:38
25 Feb 2005 09:17:39
25 Feb 2005 09:17:40
25 Feb 2005 09:17:41
25 Feb 2005 09:17:42
25 Feb 2005 09:17:43
25 Feb 2005 09:17:44
25 Feb 2005 09:17:45
25 Feb 2005 09:17:46
25 Feb 2005 09:17:47
25 Feb 2005 09:17:48
25 Feb 2005 09:17:49
25 Feb 2005 09:17:50
25 Feb 2005 09:17:51
25 Feb 2005 09:17:52
25 Feb 2005 09:17:53
25 Feb 2005 09:18:36
24 Feb 2006 13:27:45
24 Feb 2006 16:15:58
24 Feb 2006 16:15:58
24 Feb 2006 16:15:56
24 Feb 2006 16:15:56
24 Feb 2005 13:09:36
);

#open (TEST, "TradingManager_ckt49_h.log") || die "no data to check:$!\n";
#open (LOGFILE, "logfile.txt") || die " no log file:$!\n";
#open (ERRORFILE, ">>errorfile.txt") || die " no error file:$!\n";

my $last_runtime = $logfile[$#logfile];

print $last_runtime;
my $max_runtime;
my $x = 1;
while (<DATA>) {
if ($x) {
my $comp_string = substr( $_, 0, 20 );
if ( ( $last_runtime eq $comp_string ) ) { $x = 0;
print("whooooo\n") }
print( $comp_string, "\n" );

}
else {

#print (" found the starting point\n");
if (/ERROR.*Msg: 249/) {
print $_;

#print ("we are here");
#print errorfile $_;
}
}
$max_runtime = substr( $_, 0, 20 );

}
print $max_runtime

#open (logfile, ">>logfile.txt") || die " no log file";
#print logfile $max_runtime, "\n";
#close (test);
#close (logfile);
#close (errorfile);

__DATA__
24 Feb 2005 13:01:11 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:02:21 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:03:21 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:04:21 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:05:28 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:06:36 WARNING - <executing script ***
24 Feb 2005 13:07:36 WARNING - <executing script ***

24 Feb 2005 13:09:36 WARNING - <executing script ***
24 Feb 2005 13:10:36 WARNING - <executing script ***
24 Feb 2005 13:11:36 WARNING - <executing script ***
24 Feb 2005 13:12:54 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:13:55 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:14:12 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:15:12 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2005 13:16:45 ERROR - <gmem_table_sort.c, line #8088>:
TABLE_PivotInternal(): ***
24 Feb 2006 16:15:58 ERROR - <prc_gui.c, line #2503>: ***
25 Feb 2006 09:17:36 ERROR - <db_api_ct.c, line #2120>: ***
21 Feb 2005 13:56:59 ERROR - <db_api_ct.c, line #241>: *** Msg: 249,
***
21 Feb 2005 13:56:59 ERROR - <db_api_ct.c, line #241>: *** Msg: 248,
***
24 Feb 2006 13:27:45 ERROR - <gmem_table_sort.c, line #8110>:
TABLE_PivotInternal(): ***
21 Feb 2005 13:56:59 ERROR - <db_api_ct.c, line #241>: *** Msg: 249,
***
24 Feb 2006 13:27:46 ERROR - <gmem_table.c, line #7770>: ***
24 Feb 2006 16:15:56 ERROR - <prc_pv.c, line #1309>: ***






All times are GMT. The time now is 10:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.