Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Matching numeric digits in strings

by Samy_rio (Vicar)
on Jan 10, 2007 at 12:37 UTC ( #593895=note: print w/ replies, xml ) Need Help??

in reply to Matching numeric digits in strings

Hi flemi_p, this will help you if I understood your question correctly.

use strict; use warnings; open(IN, 'E:\test\infile.txt') || die $!; my @infile = <IN>; close(IN); open(RE, 'E:\test\require.txt') || die $!; my @reqids = <RE>; close(RE); chomp @infile; chomp @reqids; for my $index (0..$#infile){ for my $rindex (0..$#reqids){ if ($infile[$index] =~ m/$reqids[$rindex]/){ if ($infile[$index] =~ m/select/i){ my $count = $index; $count += 3; print "$infile[$_]\n" for ($index..$count); } } } } __END__ Output as: ---------- 15:53:43.908 Dbg 10739 Oracle: id='12.1' req='834531' SQL: SELECT crf_ +routing.CRF_RT_ACD1_QUEUE,crf_routing.CRF_RT_ACD1_SIZE,crf_ro' +0551 Executed SQL statement 'SELECT', start retrieve records... +0826 MSG_RETRIEVED2 status='DBM_SUCCESS' +0826 MSG_RETRIEVED status='DBM_NOMORE'

Updated Thanks davorg.

Velusamy R.

eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Comment on Re: Matching numeric digits in strings
Select or Download Code
Replies are listed 'Best First'.
Re^2: Matching numeric digits in strings
by davorg (Chancellor) on Jan 10, 2007 at 12:53 UTC
    map{chomp($_)}@infile; map{chomp($_)}@reqids;

    I think you mean:

    chomp @infile; chomp @reqids;

    Isn't that simpler?


    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re^2: Matching numeric digits in strings
by flemi_p (Novice) on Jan 10, 2007 at 14:48 UTC
    Hi Velusamy R.,

    Thanks for this. It works fine. However, I need all lines matched with the reqid, which includes the line with the reqid and a select, and the 3 lines in the log file after a line with a select. This constitutes all data for a reqid in the log file and I need them to be output together in the order they are in the log file. Apologies, I didn't explain this very well originally.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://593895]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2015-10-05 00:19 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (105 votes), past polls