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)[0];
I get just the match but it also alters the array
Both `map` and `grep` will process *every* element of `@ret before
producing a result, even if the first element matches.
The most efficient is a `for` loop, like this
use strict;
use warnings;
my @ret = (
'# Line 1',
'# ARIN WHOIS data and services are subject to the Terms of Use',
'# Line 3',
);
my $src;
for (@ret) {
if (/(ARIN|APNIC)/) {
$src = $1;
last;
}
}
which prints `ARIN`.
HTH,
Rob
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/