http://qs1969.pair.com?node_id=367528


in reply to Need help to parse the text

Your first problem is that the format of ifconfig -a may be different on different platforms. For example:

[root]# uname -s Linux [root]# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:C0:9F:XX:XX:XX inet addr:64.x.x.x Bcast:64.x.x.x Mask:255.255.254.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:193891504 errors:0 dropped:0 overruns:0 frame:0 TX packets:153456331 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:1718775511 (1639.1 Mb) TX bytes:3265401055 (3114.1 + Mb) Interrupt:16 Base address:0xecc0 Memory:fe100000-fe120000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:56540745 errors:0 dropped:0 overruns:0 frame:0 TX packets:56540745 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2665326103 (2541.8 Mb) TX bytes:2665326103 (2541.8 + Mb)

Anyway you need to find a good way to chunkify the data into records. Assuming you get it in a scalar split "\n\n" should probably do the trick. Then the first string in your chunk is the interface name and m/status:\s+(\S+)/ will give your status. That won't work on Linux.

for my $chunk (split "\n\n", $data) { my ($if) = $chunk =~ m/^(\S+)/; my ($status) = $chunk =~ m/status:\s*(\S+)/; print "$if: $status\n"; }

cheers

tachyon