in reply to Re^2: What is the best way to handle this data?
in thread What is the best way to handle this data?

Your input is simple enough that you could parse it using split, but for anything more complex, you should heed kennethk's advice. Here is the parsing piece; I'll leave the printout as an exercise for you:
use strict; use warnings; use Data::Dumper; my %data; while (<DATA>) { chomp; my ($lot, undef, $make, undef, $city, $state) = split /,/; $data{$lot}{$make}++; $data{$lot}{location} = "$city,$state"; } print Dumper(\%data); __DATA__ lot1,new,honda,civic,cincinnati,oh lot1,used,chevy,impala,cincinnati,oh lot1,new,honda,civic,cincinnati,oh lot1,used,chevy,impala,cincinnati,oh lot1,new,cadillac,escalade,cincinnati,oh lot2,new,buick,sentry,houston,tx lot2,used,ford,ranger,houston,tx lot2,new,buick,sentry,houston,tx lot2,used,ford,ranger,houston,tx lot2,used,ford,ranger,houston,tx lot3,new,ford,ranger,lexington,ky lot3,used,cadillac,escalade,lexington,ky lot3,used,cadillac,escalade,lexington,ky lot4,new,ford,f150,chicago,illinois lot4,new,ford,f150,chicago,illinois lot4,new,ford,f150,chicago,illinois

which prints out;

$VAR1 = { 'lot3' => { 'location' => 'lexington,ky', 'ford' => 1, 'cadillac' => 2 }, 'lot1' => { 'location' => 'cincinnati,oh', 'cadillac' => 1, 'chevy' => 2, 'honda' => 2 }, 'lot2' => { 'location' => 'houston,tx', 'ford' => 3, 'buick' => 2 }, 'lot4' => { 'location' => 'chicago,illinois', 'ford' => 3 } };

Replies are listed 'Best First'.
Re^4: What is the best way to handle this data?
by terminaljunkie (Initiate) on Apr 28, 2009 at 19:16 UTC
    awesome. that works great. one more quick question... what would be the best way to remove any trailing/leading whitespace from the elements, as some of them have it? i know how to remove leading/trailing whitespace... but is there a way to do it on the current hash?
      You should remove whitespace before loading data into the hash, not after it is in the hash, especially if the hash keys have whitespace.