in reply to Matching words
But as Fletch suggested, if your input is really JSON data, you should use a JSON parser and handle the input as the data structure that it really is.use strict; use warnings; my @required = qw( name timestamp dl_retransmits_pct dl_throughput mac + ); my $req_regx = join( '|', @required ); while (my $line = <DATA>) { my %matched = map{ $_ => undef } $line =~ /($req_regx)/g; print $line if scalar( keys %matched ) == scalar( @required ); } __DATA__ mac timestamp name dl_retransmits_pct dl_throughput is a hit mac timestamp name dl_retransmits_pct throughout is a miss name timestamp dl_retransmits_pct dl_throughput is a miss foo mac name dl_throughput name timestamp name dl_retransmits_pct mac +mac is a hit name timestamp dl_retransmits_pct is a miss dl_throughput is a miss
(updated to fix grammar and spelling)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Matching words
by AnomalousMonk (Archbishop) on Feb 27, 2022 at 22:38 UTC |