in reply to hashes recursively
#!/usr/bin/perl -w use strict; use Data::Dumper::Simple; my %data; while (<DATA>) { chomp; my @fields = split /=/; my $depth = scalar @fields; if ($depth == 1) { $data{$fields[0]} = undef; } elsif ($depth == 2) { $data{$fields[0]} = $fields[1]; } elsif ($depth == 3) { $data{$fields[0]}{$fields[1]} = $fields[2]; } } print Dumper(%data); __DATA__ a = ID = 1234 b=Gadens_Melb c= d= e=2006-03-27 15:10:06 f= ContactSensor:INPUT2 g=Critical h=Event-101 fatal stack error on PRI 001
Output:
%data = ( 'e' => '2006-03-27 15:10:06', 'c' => undef, 'a ' => { ' ID ' => ' 1234' }, 'h' => 'Event-101 fatal stack error on PRI 001', 'g' => 'Critical', 'b' => 'Gadens_Melb', 'd' => undef, 'f' => ' ContactSensor:INPUT2' );
Cheers,
Darren :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |