Advertisement

01.21.2008 at 01:43AM PST, ID: 23097762
[x]
Attachment Details

perl extract data from filehandle

Asked by gormenghast in Perl Programming Language

Tags: perl, extract, data, from

Hi,
I am building a hash from an open filehandle. Example data shown below...

Hostname              : myhost
 Network Card e1000g0   : 0:0:0:0:0:0
         Speed         :  
         IP Address    : 172..1.1.1    : myhostI3
         Netmask       : 255.255.254.0
 Network Card e1000g0:1   :
         Speed         : ## Virtual IP ##
         IP Address    : 172.1.1.3   : myhost  myhost.com
         Netmask       : 255.255.255.0
 Network Card e1000g0:2   :
         Speed         : ## Virtual IP ##
         IP Address    : 172.1.1.2    : myhostI2
         Netmask       : 255.255.254.0
 Network Card e1000g2   : 0:0:0:0:0:0
         Speed         :  
         IP Address    : 172.1.1.4    : myhostibkup
         Netmask       : 255.255.254.0

I have extracted the hostname to the hash ...

        if ($_ =~ /^(\s)*Hostname(\s)*:/) {
        chop;
        ($pants, $details{"Hostname"}) = (split /: /);
        }

I am only interested in the primary network interface and I can get the IP address line for the primary hostname ...

        if ($_ =~ /^(\s*IP Address\s+:)(.*:)(.*$details{"Hostname"}\s+)/) {($pants, $details{"IPAddress"}) = (split /: /)}

But I am not sure how to extract the Netmask detail following on the next line to $details{"Netmask"} ensuring that I get the Netmask belonging to the primary interface and ignoring the others.

Hope this makes sense.
Start Free Trial
 
Loading Advertisement...
 
[+][-]01.21.2008 at 08:07AM PST, ID: 20707012

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 08:49AM PST, ID: 20707406

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 08:51AM PST, ID: 20707434

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 11:32AM PST, ID: 20708819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 11:50AM PST, ID: 20709030

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.21.2008 at 11:51AM PST, ID: 20709037

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, extract, data, from
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: B
 
 
[+][-]01.25.2008 at 11:46AM PST, ID: 20745685

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628