"Pat Rice" schreef:

> I'm wondering if there is a nice way to parse this data, as in is
> there any module that could handle this type of data, as in the was it
> is presented? so that I can repeat is itn a tree like structure in
> HTML ?

Maybe you are looking for something like this:

#!/usr/bin/perl -l
  use strict; use warnings;
  use Data::Dumper;
  $Data::Dumper::Sortkeys = $Data::Dumper::Indent = 1;

  my @data = map [/^(\s+)\W+([\w\s]*\w)(?:\.+(.*))?/], <DATA>; # parse
  $_->[0] = length $_->[0] for @data; # indent-width
  0 and print Dumper([EMAIL PROTECTED]); # for debugging

  my (%tree, @keys);
  for my $i (0 .. $#data) {
      my $j = $i;
      pop @keys while --$j >= 0 and $data[$i][0] < $data[$j][0];
      pop @keys if $i > 0 and $data[$i][0] == $data[$i-1][0];
      push @keys, $data[$i][1];
      $tree{join "/", @keys} = $data[$i][2];
  }
  print Dumper(\%tree);

__DATA__
  \==+Interface :
            |----Link State.................................Down
            \==+SCSI Interface :
               |----Name....................................vmhba1
               |----Console Name............................scsi1
               |----Queue Depth.............................4096
               \==+PCI Device :
                  |----Bus..................................0x0b
                  |----Slot.................................0x00
                  |----Function.............................0x00
               \==+Scsi Stats :
                  |----Commands.............................48632378
                  |----Blocks Read..........................1862894689
                  |----Blocks Written.......................858120919
                  |----Aborts...............................0


which outputs:

$VAR1 = {
  'Interface' => undef,
  'Interface/Link State' => 'Down',
  'Interface/SCSI Interface' => undef,
  'Interface/SCSI Interface/Console Name' => 'scsi1',
  'Interface/SCSI Interface/Name' => 'vmhba1',
  'Interface/SCSI Interface/PCI Device' => undef,
  'Interface/SCSI Interface/PCI Device/Bus' => '0x0b',
  'Interface/SCSI Interface/PCI Device/Function' => '0x00',
  'Interface/SCSI Interface/PCI Device/Slot' => '0x00',
  'Interface/SCSI Interface/Queue Depth' => '4096',
  'Interface/Scsi Stats' => undef,
  'Interface/Scsi Stats/Aborts' => '0',
  'Interface/Scsi Stats/Blocks Read' => '1862894689',
  'Interface/Scsi Stats/Blocks Written' => '858120919',
  'Interface/Scsi Stats/Commands' => '48632378'
};

-- 
Affijn, Ruud

"Gewoon is een tijger."


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to