Amichai Teumim wrote:

I created a file called data.txt which contains a bunch of junk, including
some IPs. I want $line to be  stored in
$ip<http://www.tek-tips.com/viewthread.cfm?qid=1382614&page=1#>
.

It works, except for the regular expressions which should find only IPs. If
I use the regular expression with the grep command in terminal I get only
the IPs. Here in Perl I don't get any output.

#!/usr/bin/perl

@input = `cat ~/ip.txt`;

foreach $line (@input){
if($line =~ /[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}/){
 $ip = $line;
 print $ip;
 }
}

Any ideas? It's breaking my head.

Perl doesn't require the braces to be escaped. As it is the regex is matching 
literal
braces in the string which don't exist. Try this:

 if ($line =~ 
/[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/) {
   :
 }

and, by the way, [0-9] is more concise than [[:digit:]].

HTH,

Rob

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


Reply via email to