Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

String matching question

by vonman (Acolyte)
on Mar 13, 2001 at 20:58 UTC ( [id://64149]=perlquestion: print w/replies, xml ) Need Help??

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

I have a log file with lines that look like [2001/03/12 08:45:38 INFO AVTransaction Compiled Code] Abandon transaction: SYcadChangeOrder:30915 After figuring out transaction numbers I need to scour another logfile to find any match in any line with the $transaction_id. In this case the trans number is 30915. The following snippet doesnt find the match. What am I doing wrong?
open (PROLOG,"$provision_log") || die "Cannot open the + file: $!"; while (<PROLOG>) { chomp; $pro_logline=$_; print "$pro_logline\n"; if ($pro_logline =~ /$transaction_id/) { print "We found a match\nPro_log:$pro_logline\ +nAuditlog $logline\n"; $jhg=<STDIN>; } # End of if prolog } # End of while for Prolog run close (PROLOG);
Thanks in advance!!! RV

Replies are listed 'Best First'.
Re: String matching question
by arturo (Vicar) on Mar 13, 2001 at 21:07 UTC

    There's not a lot to go on here. Could you give us an example of the format of the lines in the file $provision_log ? Are you sure you've captured the transaction IDs correctly? (print them out to make sure).

    Based on the format you've given, the transaction ID should be capturable by:

    my ($transaction_id) = $transaction_line =~ /:(\d+)$/;

    (be sure to wrap that in an if to make sure you're getting a match!)

    Oh, and a little 'elegantizer' for reading from the PROLOG file handle:

    while (my $pro_logline = <PROLOG>) { chomp $pro_logline;

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Re: String matching question
by andye (Curate) on Mar 13, 2001 at 21:40 UTC
    vonman, what's in $provision_log ? Just a filename? Would  open(PROLOG,"< $provision_log") be more explicit?

    andy.

Re: String matching question
by vonman (Acolyte) on Mar 13, 2001 at 21:12 UTC
    I'll give a few more entrys from the provisioning logfile.
    [2001/03/12 08:45:38 DEBUG ActivatorClient Compiled Code] Abandon tran +saction [2001/03/12 08:45:38 INFO AVTransaction Compiled Code] Abandon transac +tion: SYcadChangeOrder:30915 [2001/03/12 08:45:41 DEBUG CreatorSecurityImpl Compiled Code] Calling +getPermissionInfo:To1063mC14901973313517247At [2001/03/12 08:45:41 DEBUG CreatorSecurityImpl Compiled Code] Calling +resetSession:To1063mC14901973313517247At
    I am sure that the trans number is coming up with 30915 (I print it out in the code before this) Thanks.

      Given what pops up in those DEBUG lines, you probably shouldn't be searching for anything so simple as a match for your transaction ID (that sequence of numbers could, it appears, pop up in those long strings of digits in those lines).

      I still don't see why your code isn't producing matches. Since you don't appear to be using strict, all your variables are global, so it shouldn't be a scoping issue. Perhaps if you posted (in this thread) the part of the code that fetches the transaction IDs, we might see what's going on.

      Philosophy can be made out of anything. Or less -- Jerry A. Fodor

        Unfortunately in the complex log that I have to parse after finding a problem the only similar key is the transaction id.
Re: String matching question
by vonman (Acolyte) on Mar 13, 2001 at 21:15 UTC
    FYI. $transaction_id is a variable that I have already defined. I am trying to match with that variable.
Re: String matching question
by vonman (Acolyte) on Mar 13, 2001 at 21:22 UTC
    Even if I explicity set the $transaction_id in the first line with $transaction_id="30915"; It still wont find a match.
Re: String matching question
by athomason (Curate) on Mar 13, 2001 at 23:45 UTC
    I don't see anything broken in this code, so the bug is either more subtle than I can see through or it's hiding outside of this snippet. I was about to suggest checking for a trailing newline on your transaction ID, but setting it explicitly would have revealed that one. The other easy error would be if $transaction_id was set incorrectly (via typo in its name, for instance). If those aren't it, it's time to get your hands a bit dirtier.

    You seem to be going through most of the requisite error-finding steps, but there are a couple of other things you might try to pin down the bug. First, turn on use strict and warnings (#!/usr/bin/perl -w) if you haven't already, which it seems. You'll have to declare all your variables, but you'll thank yourself in the long run. If that doesn't uncover anything, progressively simplify your code until it does work. For instance, explicitly put a numeric ID you know exists (i.e. because the script prints it from the print "$pro_logline\n" statement) in the regexp instead of /$transaction_id/. If that doesn't work, something wacky is going on. If it does (and it should), compare each $transaction_id you search for against the known ID. You should see at least one match there; if not, the ID is somehow being read incorrectly.

Re: String matching question
by vonman (Acolyte) on Mar 14, 2001 at 02:08 UTC
    Thanks all for your help. I finally figured out my problem. I was sending the wrong value into $transaction_id. Once I found that everything worked. Thanks again.
Re: String matching question
by buckaduck (Chaplain) on Mar 14, 2001 at 00:00 UTC
    Let's narrow it down a little bit. Replace the code:
    if ($pro_logline =~ /$transaction_id/) {
    with the following:
    if ($pro_logline =~ /30915/) {
    This might give us a clue about where to look next...

    Update: I'm getting downvoted? That's funny, the response below seems to indicate that I was right...

    buckaduck

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://64149]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found