jalewis2 has asked for the wisdom of the Perl Monks concerning the following question:
In the above, I'd like to read each section and put the results for the record in a hash, with the left part of the = as the label and the right part as the data, like so; $hash{$label} = $data; Then after each record I can print the labels I'm interested in.messages:Dec 17 09:41:08 10.14.93.7 ns5xp: NetScreen device_id=ns5xp system-notification-00257(traffic): start_time="2002-12-17 09:45:58" d +uration=5 policy_id=0 service=tcp/port:8000 proto =6 src zone=Trust dst zone=Untrust action=Permit sent=1034 rcvd=19829 +src=10.14.94.221 dst=10.14.90.217 src_port=1059 dst_port=8000 transla +ted ip=10.14.93.7 port=1223 messages:Dec 17 09:41:08 10.14.93.7 ns5xp: NetScreen device_id=ns5xp +system-notification-00257(traffic): start_time="2002-12-17 09:45:59" +duration=4 policy_id=0 service=tcp/port:8000 proto =6 src zone=Trust dst zone=Untrust action=Permit sent=722 rcvd=520 src +=10.14.94.221 dst=10.14.90.217 src_port=1060 dst_port=8000 translated + ip=10.14.93.7 port=1224
I'm just not getting lookaheads and have been having trouble finding an example like my data. Any pointers?while ( /^(.+)\=(.+?)(?=^.+?:)/mgso ) { $label = $1; $data = $2; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing text files with a regex lookahead
by graff (Chancellor) on Sep 17, 2007 at 22:03 UTC | |
by jalewis2 (Monk) on Sep 24, 2007 at 18:15 UTC | |
|
Re: Parsing text files with a regex lookahead
by eff_i_g (Curate) on Sep 17, 2007 at 20:48 UTC | |
by jalewis2 (Monk) on Sep 24, 2007 at 18:11 UTC |