in reply to Can't read files content
use strict; use Data::Dumper; my $i = 0; my %records; while(<DATA>){ my($key, $val); if (/^$/){ #end of record $i++; next; } ($key, $val) = ($1, $2) if /(\w+)\s+:.(\d+) /; ($key, $val) = ($1, $2) if /(\w+)\s+:.>(.*)</; ($key, $val) = ($1, $2) if /(\w+)\s+:.'(.*)'/; $records{$i}{$key}=$val; } print Data::Dumper->Dump([\%records],[qw/records/]); __DATA__ Name : >Mick< [Mick] IC : '91919191929' [9191919129] PC : 123 [123] Number : >1960132400000< [1960132400000] Location : >000e 0036< [000e 0036] extension : >< Capability : >"CARES< ["CARES] Info : >6005494c523142< [6005494c523142] Name : >Nick< [Nick] IC : '1235467000' [1235467000] PC : 124 [124] Number : >1960192500000< [1960192500000] Location : >000f 0034< [000f 0034] extension : >< Capability : >< Info : >< Name : >Nick< [Nick] IC : '1235467000' [1235467000] PC : 124 [124] Number : >< [00] Location : >000f 0034< [000f 0034] extension : >< Capability : >.< Info : ><
OUTPUT:$records = { '1' => { 'Capability' => '', 'extension' => '', 'PC' => '124', 'Number' => '1960192500000', 'IC' => '1235467000', 'Info' => '', 'Location' => '000f 0034', 'Name' => 'Nick' }, '0' => { 'Capability' => '"CARES', 'extension' => '', 'PC' => '123', 'Number' => '1960132400000', 'IC' => '91919191929', 'Info' => '6005494c523142', 'Location' => '000e 0036', 'Name' => 'Mick' }, '2' => { 'Capability' => '.', 'extension' => '', 'PC' => '124', 'Number' => '', 'IC' => '1235467000', 'Info' => '', 'Location' => '000f 0034', 'Name' => 'Nick' } };
This is a hoh, just as easily could be a AoH's...
JamesNC
- Comment on Re: Can't read files content
- Select or Download Code
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Can't read files content
by bh_perl (Monk) on Jul 16, 2003 at 02:31 UTC |