Home: Perl Programming Help: Beginner:
Parse text file



shanti.dhanus
New User

Nov 14, 2012, 12:32 AM


Views: 4186
Parse text file

Hi,

I have to parse below text file

Chassis: ch_09USE127C72T
========================
NAME : ch_09USE127C72T
HARDWARE_UNIT_TYPE : 9730
SERIAL_NUMBER : 09USE127C72T
MONITORING_HOST : x9730-node1
OVERALL_HEALTH_STATUS : DEGRADED

Servers
=======
NAME BAY
----------- ---
x9730-node1 1
x9730-node2 2

BladeEnclosure
==============
TYPE : bladeEnclosure
NAME : OA-984BE16182A9
UUID : 09USE127C72T
SERIAL_NUMBER : USE127C72T
MODEL : -
FIRMWARE_VERSION : -
STATUS : DEGRADED
LOCATION : -
PROPERTIES : -
MESSAGE : -
DIAGNOSTIC_MESSAGE : -

And it should return 3 separate arrays as below..

Array1
--------------------------------------------
Chassis: ch_09USE127C72T
========================
NAME : ch_09USE127C72T
HARDWARE_UNIT_TYPE : 9730
SERIAL_NUMBER : 09USE127C72T
MONITORING_HOST : x9730-node1
OVERALL_HEALTH_STATUS : DEGRADED

Array2
--------------------------------------------
Servers
=======
NAME BAY
----------- ---
x9730-node1 1
x9730-node2 2


Array3
--------------------------------------------
BladeEnclosure
==============
TYPE : bladeEnclosure
NAME : OA-984BE16182A9
UUID : 09USE127C72T
SERIAL_NUMBER : USE127C72T
MODEL : -
FIRMWARE_VERSION : -
STATUS : DEGRADED
LOCATION : -
PROPERTIES : -
MESSAGE : -
DIAGNOSTIC_MESSAGE : -


Please help me on this! I am very very new to perl!


(This post was edited by shanti.dhanus on Nov 14, 2012, 12:33 AM)


rovf
Veteran

Nov 14, 2012, 1:55 AM


Views: 4178
Re: [shanti.dhanus] Parse text file


Quote
Please help me on this! I am very very new to perl!


Sure, but you need to be more specific. Where exactly are you stuck? Best is you post part of your code where you are in trouble.
Also it helps if you tell us which other programming language(s) you are already fluent in.

One general suggestion: As a Perl beginner, start evey program with the following lines:


Code
use strict; 
use warnings FATAL => qw(all);
use diagnostics;


Once you are experienced enought, you can taylor this section according to your needs...


Laurent_R
Veteran / Moderator

Nov 14, 2012, 3:17 AM


Views: 4176
Re: [rovf] Parse text file

Parsing a file is one thing, but we would need to know what you want to do with the data afterwards.