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