Thanks Dave for the while <FH> loop,  

I need to protect against blank lines and spurious white space that could show
up in the data. No doubt the file will edited in Note pad (on widows 98), and I
want to put the data in to the hash in a clean format.  and since the this is
basically a price list names of the product (the keys for the hash) might have
spaces: new model , 20 I do want them quoted: "new model"

also of note  Data::Dumper;  is built in to OSX! Joy!

Thanks for any refinement on the code below.

Dave 
( kora musician / audiophile / web master @ cora connection /  Ft. Worth, TX, USA)
 ------


#!/usr/bin/perl -w
use Data::Dumper; 
use strict;

my %prices;

my $data = "/Users/dowda/Desktop/tmp test/test.txt";

open (FH,$data)  || die  "could not open $data $!";

while( <FH> ) {
s/^\s*(.+)\s*$/$1/; # clean the line
next if m/^\W+/;  # blank lines

    my( $k, $v ) = split /,/;

$k =~ s/^\s*(.+)\s*$/$1/; # clean the hash key
$v =~ s/^\s*(.+)\s*$/$1/; # clean the value

    $prices{qq($k)}  = $v; 
}

close FH;

for my $key (keys %prices) {
    print "$key = $prices{$key}\n";
}


print "\n\n" , Dumper \%prices;

__DATA__

 model-old  ,22
model new,  34  

model new with crome, 48
last years model,10  


model 2a , 100

==============================================
         Cora Connection: Your West African Music Source
              Resources, Recordings, Instruments & More!
                   <http://www.coraconnection.com/> 
==============================================

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to