in reply to Suggestions & Improvements on a portscanner using IO::Socket

I think you can greatly simplify expand_ports.
# Warning: untested... sub expand_ports { my $port = shift; my %ports; foreach my $range (split /\s*,\s*/, $port) { if ($range =~ /^\d+$/) { $ports{$range}++; } elsif ($range =~ /^\s*(\d+)\s*-\s*(\d+)\s*$/) { @ports{$1..$2} = ($1..$2); } else { die "Bad port spec"; } } return sort keys %ports; }

split() doesn't care very much if there aren't any commas, so you don't need to treat the "no commas" cases as special cases. Storing the found ports as hash keys implicitly removes duplicates. In my example I don't care about the values at all, so I just use the most convenient method of setting the hash keys to any old value in each case.

I'm sure someone will find some typos or minor syntax errors there, I just wanted to get the general idea across :) I hope this helps.

Alan