Re: return just a match from an array without changing the array

2014-03-08 Thread Janek Schleicher
Am 04.03.2014 00:35, schrieb shawn wilson: 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/} @r

Re: return just a match from an array without changing the array

2014-03-04 Thread Dr.Ruud
On 2014-03-04 00:35, shawn wilson 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 First understand what you coded: grep() is a filter: it only passes

Re: return just a match from an array without changing the array

2014-03-04 Thread Rob Dixon
On 03/03/2014 23:35, shawn wilson 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

Re: return just a match from an array without changing the array

2014-03-04 Thread shawn wilson
On Mar 4, 2014 9:46 AM, "Shawn H Corey" wrote: > > On Tue, 4 Mar 2014 09:24:53 -0500 > shawn wilson wrote: > > > my $src = (map {s/.*(ARIN|APNIC).*(?:\n)?/$1/r} @ret)[0]; > > You do realize this is process the whole array and then throwing out > all but the first? And it has the side effect of mo

Re: return just a match from an array without changing the array

2014-03-04 Thread Shawn H Corey
On Tue, 4 Mar 2014 09:24:53 -0500 shawn wilson wrote: > my $src = (map {s/.*(ARIN|APNIC).*(?:\n)?/$1/r} @ret)[0]; You do realize this is process the whole array and then throwing out all but the first? And it has the side effect of modifying the array? -- Don't stop where the ink does.

Re: return just a match from an array without changing the array

2014-03-04 Thread shawn wilson
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)); $soc

Re: return just a match from an array without changing the array

2014-03-03 Thread Shawn H Corey
On Mon, 3 Mar 2014 18:35:55 -0500 shawn wilson 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 If you can't figure out what's wrong, neither wil

Re: return just a match from an array without changing the array

2014-03-03 Thread Ken Slater
I think you want to use 'map' instead of grep. HTH, Ken On Mon, Mar 3, 2014 at 6:35 PM, shawn wilson 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 o