simple help

Discussion in 'Perl Misc' started by jaw56856@yahoo.com, Mar 22, 2005.

  1. Guest

    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??
     
    , Mar 22, 2005
    #1
    1. Advertising

  2. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 22, 2005
    #2
    1. Advertising

  3. Guest

    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?
     
    , Mar 23, 2005
    #3
  4. 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.
     
    Arndt Jonasson, Mar 23, 2005
    #4
  5. Guest

    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");
    }

    }
     
    , Mar 23, 2005
    #5
  6. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 23, 2005
    #6
  7. Guest

    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
     
    , Mar 25, 2005
    #7
  8. Paul Lalli Guest

    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
     
    Paul Lalli, Mar 25, 2005
    #8
  9. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 25, 2005
    #9
  10. lynn Guest

    <> wrote in message
    news:...
    > 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>: ***
     
    lynn, Mar 25, 2005
    #10
  11. lynn <> wrote:
    ><> wrote in message
    > news:...


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



    But the problem would have gone away during the exercise
    of constructing the small program, and the solution would
    have become evident *before* asking hundreds of other people
    to help with it.

    (this is precisely the purpose of including that suggestion
    in the guidelines.
    )


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


    > my @logfile = qw(
    > 25 Feb 2005 09:17:35



    After the OP changed it up to load directly rather than from
    a file, the problem would have gone away, and it could be
    seen where the problem originated.

    The OP's problem was a missing chomp().


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 25, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    585
  2. Kevin Spencer

    Re: Simple Simple question!!!

    Kevin Spencer, Jun 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    694
    Kevin Spencer
    Jun 25, 2004
  3. Dave E
    Replies:
    7
    Views:
    771
    Josh Twist
    Jan 11, 2006
  4. Daniel Frey

    Simple Question - Simple Answer?

    Daniel Frey, Dec 28, 2004, in forum: XML
    Replies:
    4
    Views:
    871
    Daniel Frey
    Jan 12, 2005
  5. Replies:
    14
    Views:
    556
    Karl Heinz Buchegger
    Nov 2, 2005
Loading...

Share This Page