Beginner wrote:
> On 26 Feb 2007 at 15:58, D. Bolliger wrote:
>>
>>#!/usr/bin/perl
>>
>>use strict;
>>use warnings;
>>
>>{
>>  local $/="}\n";
>>  for (<DATA>) {
>>    my ($ip,$mac,$host)=
>>       /lease\s+(\S+).*
>>        ethernet\s+(\S+);.*
>>        hostname\s+(\S+);
>>       /sx;    
>>    print "IP $ip - MAC $mac - HOST $host\n";
>>  }
>>}
> 
> That's worked a treat. Just to complete the learning curve, where was 
> I going wrong?


> while (<FH>) {
>         chomp;
>         ($ip,$mac,$host) = ($_ =~ 
> /lease\s+(\d{3}\.\d{3}\.\d{3}\.\d+)

IP addresses can contain one, two or three digits for each octet so \d{3} will
not match all addresses.


>.*thernet\s+(\d{2}:\d{2}:\d{2}:\d{2}:\d{2}:\d{2})

MAC addresses consist of hexadecimal digits but \d only matches decimal digits.


>.*ostname\s+\"(\w+\.scien.*)"/smg);

None of the host names in your example contained the string 'scien'.


>         print "$ip $mac $host\n";
> 
> }



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall

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


Reply via email to