Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting records of various lengths from single text file

Status
Not open for further replies.

Nalyd

Technical User
Mar 16, 2002
16
0
0
US
I'm trying to read data records from a telco system. It's a plain text capture, but the records have different lengths.

Depending on the amount of features ('FTR' towards the end in the listing), some records may contain fewer or more lines than this one. Every record starts with 'DES' and ends with a 'DATE' line.

Every record has a unique Terminal Number (TN). I'm just starting with Perl (finally gave up on Procomm), and I'm having trouble figuring out how to read read a single record into a hash. To be honest, I'm not even sure if I should use hash keys or single scalars for each entry.

I appreciate any help ;)




--- Start of listing ---
DES LBALIB
TN 000 0 03 02
TYPE 500
CDEN SD
CUST 0
DN 5028 1 MARP
AST NO
IAPG 0
HUNT 5019
TGAR 1
LDN NO
NCOS 5
SGRP 0
RNPG 32
XLST
SCI 0
CLS CTD DTN FBD XFA WTA THFD FNA HTD ONS
LPR XRA CWD SWD PUA MWD RMMD SMWD LPD XHD SLKD
CCSD LND TVA CFTD SFD C6D CNID CLBD AUTU
ICDD CDMD EHTD MCTD
GPUD DPUD CFXA ARHD OVDD AGTD CLTD LDTD ASCD
MBXD CPFA CPTA DDGA NAMA
MCRD SHL ABDD CFHD
USRD BNRD RTDD RBDD RBHD FAXD PGND FTTU
RCO 0
PLEV 02
AACS NO
FTR CFW 4
FTR PHD
FTR FDN 5019
FTR RDL 16
DATE 14 MAR 2002
--- End of Listing ---
 
Hi there,

What do you want to do with the data?

To get you started maybe, here's a way you can read the single line data into a hash using the first word as the key.

while(<>){
chomp;
($key, $rest) = split(/\s+/,$_,2);
$hash{$key};
}

You can then loop through the hash like this.

foreach $key (%hash){
print &quot;$key=$hash{$key}\n&quot;;
}

You'll notice that it doesn't print them out in any sensible order though, is the order important to you?
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
>>> To get you started maybe, here's a way you can read the single line data into a hash using the first word as the key.

Thanks Mike, that's exactly what I wanted to do. I'd like to read the information into an HTML form/table, like so:

print &quot;<tr><td>$key</td><td>$hash</td><tr>\n&quot;;

Some of the cells will be form fields with the hash value as the default option. The only exception is the Class Of Service entries (8 lines starting at CLS). Most of those are either Allowed or Denied, and will be a checked or unchecked form item. For example, HTA=Hunting Allowed, HTD=Hunting Denied.
It gets tricky with the ones that can have completely different entries. The first one (CTD) can have 8 different entries. I'd like to pre-define all possible entries in strings that can be matched against the hash data, while the unmatched items will be options in a dropdown list.

I will then parse any formdata changes to a Procomm script that I can run on the switch, that is, until I find a way to directly access serial ports with Perl.

Nalyd.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top