in reply to html to hash table

Base on the content of your @list:
my $data = {}; foreach my $item ( @list ) { my $span = $tree->look_down( _tag => 'span' ); my $title = $span->as_trimmed_text() . $span->right(); for my $row ( $tree->look_down( _tag => q{tr} )) { my @keys = $row->look_down( _tag => q{th} ); my @vals = $row->look_down( _tag => q{td} ); for ( my $i = 0; $i < scalar @keys; $i++ ) { my $key = $keys[ $i ]->as_trimmed_text(); my $val = $vals[ $i ]->as_trimmed_text(); $data->{ $title }{ $key } = $val; } } } print 'data: ' . Dumper( $data ); }
Result:
data: $VAR1 = { 'CS 128 Section 01 ' => { 'Capacity' => '30', 'Building/Room' => '8 52', 'Title' => 'Introduction to C++', 'Time' => "3:00 PM\x{2013}4:50 PM\ +x{a0}\x{a0}\x{a0}TuTh", 'Class Nbr' => '11647', 'Units' => '4' } };
Look at HTML/Element for more info

Replies are listed 'Best First'.
Re^2: html to hash table
by Anonymous Monk on Oct 30, 2016 at 22:59 UTC
    Thank you it works, one more question if I want to access 'Time' for 'CS 128 Section 01' class how would i do that?
      print $data->{'CS 128 Section 01'}{Time}
      If you have more data you can loop thru it:
      foreach my $class ( keys %{ $data }) { print $data->{ $class }{Time} # do something else with other items ... }