On Mon, Nov 2, 2009 at 7:54 AM, Brent Clark <[email protected]>wrote:
> Hiya
>
> I was hoping that someone would be kind to help me.
>
> I have a string like so :
>
> Haresources : 10.203.4.5, Interfaces : 10.203.4.5 10.203.4.7
>
> Im trying to get the ip's after Interfaces into an array, but for the likes
> of me, im just not getting it right. This is what I currently got.
>
> my @h2ip = ($tmp{ $opt_H2 } =~
> /(?:Interfaces\s:\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))/gi );
>
> If someone could help, I would be most appreciative.
>
> Kind Regards
> Brent Clark
Here are a couple more options:
use strict;
use warnings;
$\ = "\n";
$, = ", ";
my $str = 'Haresources : 10.203.4.5, Interfaces : 10.203.4.5 10.203.4.7';
my @pieces = split " : ", $str;
my @ips = split " ", $pieces[-1];
foreach my $ip(@ips) {
print "--->$ip<----";
}
--output:--
--->10.203.4.5<----
--->10.203.4.7<----
@pieces = split "Interfaces", $str;
my $target = $pieces[-1];
print $target;
while ($target =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g) {
print "--->$1<---";
}
--output:--
: 10.203.4.5 10.203.4.7
--->10.203.4.5<---
--->10.203.4.7<---