It needs to be grep as a map would return the first line no matter
what - not what I want. Also, this doesn't work:

sub whois
{
  my ($whois) = @_;

  my $sock = IO::Socket::INET->new(
    PeerAddr=>$whois,
    PeerPort=>'43',
    Timeout=>'60',
  );
  return undef unless (defined($sock));

  $sock->print("n " . $ARGV[0] . "\n");
  my @ret = <$sock>;
  $sock->close;
  my $src = (map {s/.*(ARIN|APNIC).*(?:\n)?/$1/r} @ret)[0];
  print "src [$src]\n";
  @ret = grep {length($_) and not /#( .*)?/} map { s/\n//; $_ } @ret;
  return @ret;
}

Per whois, I've got tons of servers, but arin seems to have info from
most (all?) of them - so if I can get away with that, it should be
quicker (connection wise). However, I figure the easiest way to make
an etl for this is to know what server it's coming from.

On Mon, Mar 3, 2014 at 10:58 PM, Charles DeRykus <dery...@gmail.com> wrote:
>
> On Mon, Mar 3, 2014 at 3:35 PM, shawn wilson <ag4ve...@gmail.com> wrote:
>>
>> So, when I do this:
>>   my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0];
>> I get a full line and not just the capture:
>> # ARIN WHOIS data and services are subject to the Terms of Use
>>
>> When I do this:
>>   my $src = (grep {s/.*(ARIN|APNIC).*(\n)?/$1/} @ret)[0];
>> I get just the match but it also alters the array
>>
>
> The trouble is the substitute operator clobbers the $_ which map or grep
> aliases each list item to.  The non-destructive /r switch in modern perl
> versions can help (see perlop):
>
> my @hits = map { s/.../$1/r } @ret;
> my $src =$hits[0];
>
> or, maybe:
>
> my $hit = ( map { s/.../$1/r } @ret )[0];
>
> --
> Charles DeRykus
>
>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to