Hi Gunnar, I tried your suggestions but had no luck :-(
(1) I tried your idea of using a paragraph separator local $/ = ''; # paragraph mode while ( my $entry = <DATA> ) { if ( $entry =~ /\[([a-z0-9]{5})]/ ) { print "$1\n"; } } But the only output which got was : # script.pl 8252c So it found the first line and then quit. So the separator is obviously the usual "\n"; At some point, I was planning to convert the long "wrapped" lines into a single long line, to make the later timestamp analysis easier. This is how the event records appear in the log: [2009-01-25 02:21:13,760]TRACE [server-1] [http-80-12] u...@mydomain.net:090125-022113763:4c213 (LimitVoIPLineImpl.java:call:54) ;- RequestId [8252c] LimitVoIPLine.REQ { accountNumber:=W1931627, phoneNumber:=1234512345 } ;[2009-01-25 02:21:22,104]TRACE [server-1] [http-80-12] u...@mydomain.net:090125-022113763:4c213 (LimitVoIPLineImpl.java:call:57) ;- RequestId [8252c] LimitVoIPLine.RES { LimitVoIPLine Result { Result:=Success } } ;[2009-01-25 02:21:34,675]TRACE [server-1] [http-80-20] u...@mydomain.net:090125-022134678:467d0 (LimitVoIPLineImpl.java:call:54) ;- RequestId [8252d] LimitVoIPLine.REQ { accountNumber:=W1931627, phoneNumber:=31455491773 } ;[2009-01-25 02:21:41,354]TRACE [server-1] [http-80-20] u...@mydomain.net:090125-022134678:467d0 (LimitVoIPLineImpl.java:call:57) ;- RequestId [8252d] LimitVoIPLine.RES { LimitVoIPLine Result { Result:=Success } } ;[2009-01-25 09:26:27,148]TRACE [server-1] [http-80-8] u...@mydomain.net:090125-092627068:48de4 ;(GetCallForwardStatusImpl.java:call:52) - RequestId [82534] GetCallForwardStatus.REQ { accountNumber:=W1576824, phoneNumber:=1234512345 ;} ;[2009-01-25 09:26:27,153]TRACE [server-1] [http-80-12] u...@mydomain.net:090125-092627077:5d89f ;(GetRestrictionListImpl.java:call:53) - RequestId [82535] GetRestrictionList.REQ { accountNumber:=W1576824, phoneNumber:=1234512345 } So a single event record can be split across several lines ( I assume this is not just a "terminal wrap" problem). Is this what you mean when you said that "Probably because your code splits each entry into multiple @list elements." Would it be better to convert each record into a single long line before trying to perform regex match? Is there an easy way to do this? Regards, Bill Harpley -----Original Message----- From: Gunnar Hjalmarsson [mailto:nore...@gunnar.cc] Sent: Monday, January 26, 2009 5:22 PM To: beginners@perl.org Subject: Re: Simple regex problem has me baffled Bill Harpley wrote: > > [2009-01-23 09:20:48,719]TRACE [server-1] [http-80-5] > a...@mydomain.net > :090123-092048567:f5825 (SetCallForwardStatusImpl.java:call:54) - > RequestId [81e80] SetCallForwardStatus.REQ { accountNumber:=W12345, > phoneNumber:=12121212121, onBusyStatus:=true, busyCurrent:=voicemail, > onNoAnswerStatus:=false, noAnswerCurent:=voicemail, > onUncondStatus:=false, uncondCurrent:=voicemail } Is an entry divided into multiple lines? If so, and if the entries are separated by one or more empty lines, you probably want to enable paragraph mode. http://perldoc.perl.org/perlvar.html#$INPUT_RECORD_SEPARATOR > chomp(@list=<DATA>); It seems to be unnecessary to read the whole log file into an array. chomp()ing seems to be unnecessary, too. > $entry =~ /\[([a-z0-9]{5})\]/; You'd better check whether the regex matches. local $/ = ''; # paragraph mode while ( my $entry = <DATA> ) { if ( $entry =~ /\[([a-z0-9]{5})]/ ) { print "$1\n"; } } > The first thing that puzzles me is that it obviously extracting the > RequestId substring correctly, it seems to complain about the "$1\n" > expression in line 16. > This looks quite OK to me and I am baffled why I am getting this > message. Probably because your code splits each entry into multiple @list elements. > The other thing that puzzles me is that there can only be a single > REQ/RES pair in the file with a given ID. So the RequestID should not > appear more than twice in the The output list. Yet there are many > instances where the RequestID appears more than twice. $1 retains its value from the latest successful match until the next time the regex matches successfully. -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/