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

Piercer has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm trying to do something fairly simple but can't figure out whats going wrong. I'm running NBTSTAT -a on a load of IP addresses - supplied from a file NBT.CSV -It's a windoze program which gives fairly verbose output - What I'm trying to get is the first 15 characters of each line with no duplicates in comma delimited form. A fairly simple text processing job I thought - I figured without me having left my brain at home today. The code is as follows
#!c:\perl\bin\perl -w open(NB, "nbt.csv")|| die"Cant open input file nbt.csv"; # NBT.CSV simply contains ip addresses - one per line while(<NB>) {undef $line; chomp $_; $line="$_".","; @nbtstat = `nbtstat -a $_`; $len=@nbtstat; for ($j=0; $j<$len;$j++) {$short=substr($nbtstat[$j],0,15); chomp $short; unless ($line=~m/$short/) {$line=$line.",".$short;} } print "$line\n"; } close(NB);
What I get is like this - first line is correct, second line is missing the ip address at the beginning - I cant figure out why? 1.1.1.1,,Host not found.
, Name ,---------------,Registered Regi,WS12345678901,USER1,MAC Address = 0
The text this is produced from is like this
C:\Perl>nbtstat -a 1.1.1.1
Host not found.
C:\Perl>nbtstat -a 1.1.1.2
NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
WS12345678901 <00> UNIQUE Registered
EUROPE-AFRICA <00> GROUP Registered
ws12345678901 <20> UNIQUE Registered
WS12345678901 <03> UNIQUE Registered
USER1 <03> UNIQUE Registered
MAC Address = 00-06-C7-E6-D8-36
Any ideas or donations of money would be gratefully received. Thanks Andrew