Ron McKeever wrote:
> Thanks a lot, that helped. 
> But Im stuck on still printing the other IP's, basically I'm trying to group
> them. So now I can only print the ones that match. But I still need to print 
> the ones that 
> dont, like the 66 address it never prints that?
> 
> 
>>__DATA__
>>number,111.9.1.10,blah
>>number,111.9.5.55,blah
>>number,111.9.16.256,blah
>>number,111.9.20.10,blah
>>number,66.9.14.2,bah
> 
> 
> Thanks again,
> Rob
> 
> -----Original Message-----
> 
>>From: Owen Cook <[EMAIL PROTECTED]>
>>Sent: Jan 10, 2006 11:20 PM
>>To: jcht_mck <[EMAIL PROTECTED]>
>>Cc: beginners@perl.org
>>Subject: Re: loop Question
>>
>>
>>On Tue, 10 Jan 2006, jcht_mck wrote:
>>
>>
>>>I wanted to print if it matches my range of IP's. I thought I could use the
>>>(#..#) and it would work, but it didn't:
>>>
>>>#!/usr/bin/perl -nlw
>>>
>>># Print if Ip's are in 
>>># 111.9.1-18.### or 
>>># 111.9.20-100.###
>>># range
>>>#
>>>my $a="1-18";
>>>my $b="20-100";
>>>
>>>    while (<>)
>>>    {  
>>>chomp $_;
>>>next if ($_ eq "");
>>>
>>>my ( $number,$ip,$host ) = split(/,/,$_);
>>>  if ( $ip =~ /111.9.\b(1..18)\b.\d/){
>>> print "$ip";
>>>}
>>>    }
>>>exit;
>>
>>
>>Maybe you want to try something like this. It's a bit of a sledge hammer
>>approach but I think it does the job
>>
>>
>>#!/usr/bin/perl -w
>>
>># Print if Ip's are in
>># 111.9.1-18.### or
>># 111.9.20-100.###
>>
>>use strict;
>>   while (<DATA>)
>>   {
>>
>>next if /^(\s)*$/;
>>my $line = $_;
>>my ( $number,$ip,$host ) = split/,/,$line;
>>
>>if ($ip=~/(\d+\.)(\d+\.)(\d+\.)(\d+)/) {unless (($1 == 111 )and ($2 ==
>>9)){next}
>>if ((($3 > 0) and ($3 < 19))or(($3 > 19) and ($3 < 101))){
>>print " in range $3 "}}
>>print "$ip\n"}
>>
>>
>>__DATA__
>>number,111.9.1.10,blah
>>number,111.9.5.55,blah
>>number,111.9.16.256,blah
>>number,111.9.20.10,blah
>>number,111.9.20.256,blah
>>number,111.9.6.66,blah
>>number,111.9.22.22,blah
>>number,111.10.1.33,blah
>>number,111.9.111.10,blah





Well you have an 'if' statement that results in a print action if true, just
add an else to print something else if not true.



Owen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to