in reply to Last service name comes up empty in NMAP Parser

Hi Noosrep,

my $fct_openPort = (join ',',$fct_host_obj->tcp_ports('open'))."\n" ; my @fct_ports = split ',', $fct_openPort;

First of all, why first join the list of ports into a comma-separated string, only to split it back out again? Why not say for my $fct_port ($fct_host_obj->tcp_ports('open'))?

Second, note the ."\n": you're appending a newline to the end of the string, which remains there after the split. See the Basic debugging checklist, especially item 3 (unexpected whitespace)*. Remove the ."\n" and I suspect your code will work.

my @tcp_ports = qw/ 139 445 1984 /; my $fct_openPort = (join ',',@tcp_ports)."\n" ; my @fct_ports = split ',', $fct_openPort; use Data::Dumper; $Data::Dumper::Useqq = 1; print Dumper(\@tcp_ports,\@fct_ports); __END__ $VAR1 = [ 139, 445, 1984 ]; $VAR2 = [ 139, 445, "1984\n" ];

Also, you never tell us which module you're using? (I assume it's not relevant here, but you never know...)

* Update: You can already see the extra newline character in your output: "service and port = 1984 <newline> :"

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: Last service name comes up empty in NMAP Parser
by Noosrep (Novice) on Jan 18, 2017 at 11:25 UTC
    Module was NMAP::Parser, I thought that was clear from my question but I guess not :) Either way, you and Huck were right. Removing the \n was the solution..