peterw was once rumoured to have said:
> Scott Howard wrote:
> >
> > On Sun, Sep 16, 2001 at 11:39:33PM +1000, peterw wrote:
> > > Given an alpha numeric string of vaying length that contains 0 or more
> > > valid IP numbers(dotted quad decimal)and each IP(if there is one) is
> > > seperated form the next IP or other text by one or more spaces how can I
> > > use Perl to retrieve thes IP's into an array ?
> >
> > Presuming the string is in $_
> > @IP = split;
> >
> > Scott.
>
> Sorry should have explained better. String can have one or more groups
> of alpha numeric characters. Each group of chracters is seperated by one
> or more spaces. Each group can have one or more charcters. Zero or more
> of these groups may be a valid IP. The IP 's can occur anywhere in the
> string. The IP's may or may not be consecutive.
>
> If I use split how do I know which array elements are the IP's ?
Assuming $line has your line in it, you should be able to use
something like:
my @splitline = split /\s+/, $line;
my @ipaddr = ();
foreach $i (@splitline) {
if ($i =~ m/^\d+\.\d+\.\d+\.\d+$/) {
push @ipaddr, $i;
}
}
@ipaddr will then contain all the ip-like data.
the looser form regexp is preferred since dotted quad is a fairly
loosely defined structure. If you're paranoid, you can use:
if ($i =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) ...
then perform a secondary test on $1, $2, $3 and $4 to make sure
they're numerically between 0 and 255 (inclusively).
C.
--
--==============================================--
Crossfire | This email was brought to you
[EMAIL PROTECTED] | on 100% Recycled Electrons
--==============================================--
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug