in reply to hashes with arrays

Huh. Everyone wants to type a lot. :)

You're trying to create a "Hash of Arrays". Check out perldsc, the "Perl Data Structure Cookbook" for lots of examples. Here's how I created it from your example data:

#!/usr/bin/perl use strict; use warnings; my %hash = (); my $key; while( <DATA> ) { chomp; if( /^(\S.*)/ ) { $key = $1 } elsif( /^\s+(\S.*)/ ) { push @{ $hash{$key} }, $1 } elsif( /^\s*$/ ) { next; } } use Data::Dumper; print Dumper( \%hash ); __DATA__ Honda Civic Accord Toyota Camry Corolla Tundra Nissan Maxima
--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review