morgon has asked for the wisdom of the Perl Monks concerning the following question:
on OpenWrt I try to find out about visible wifi-networks by parsing the output of iw scan.
This output looks like this:
What I am interested in is the set of all ssids, each being contained in a stanza that starts with "BSS" and ends when the next "BSS" is encountered.BSS <blah blah> SSID: <ssid> <blah blah> BSS <and so on>
So I parse it like this:
And that works, but it bugs me that I manually add a "synthetic" BSS to the output of iw so I can then use a lookahead in the regex that would also match on the last entry.my $out = qx| sudo iw dev wlan0 scan |; $out .= "\nBSS"; my @chunks = $out =~ /^(BSS.*?)(?=^BSS)/smg; my @essids = map { /SSID: (.*?)$/ms; $1 } @chunks;
So I wonder: Is there a more elegant way to do this?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: more elegant way to parse this?
by tybalt89 (Monsignor) on Feb 24, 2017 at 06:39 UTC | |
|
Re: more elegant way to parse this?
by johngg (Canon) on Feb 24, 2017 at 12:09 UTC | |
|
Re: more elegant way to parse this?
by 1nickt (Canon) on Feb 24, 2017 at 12:55 UTC | |
|
Re: more elegant way to parse this?
by Anonymous Monk on Feb 24, 2017 at 16:24 UTC |