in reply to Re: How can I read a line of text from a file into an array?
in thread How can I read a line of text from a file into an array?

Brilliant! That's helped enormously, thanks. Now for the real file which has several hundred lines and 10 key value pairs :)
  • Comment on Re: Re: How can I read a line of text from a file into an array?

Replies are listed 'Best First'.
Re: Re: Re: How can I read a line of text from a file into an array?
by dvergin (Monsignor) on Jul 18, 2001 at 03:27 UTC
    In that case (and you may already have this worked out) if you are building one great big hash, the main code would look something like:
    open HANDLE, 'testhash.txt' or die "Can't open: $!"; my %hash; for my $data (<HANDLE>) { chomp $data; foreach my $pair (split /'/, $data) { next if $pair eq ''; next if $pair =~ /^,$/; my ($key, $value) = split /,/, $pair; $hash{$key} = $value; } } close HANDLE; # do stuff with entire hash here
    Or if you are doing something with the hash line-by-line:
    open HANDLE, 'testhash.txt' or die "Can't open: $!"; for my $data (<HANDLE>) { chomp $data; my %hash; foreach my $pair (split /'/, $data) { next if $pair eq ''; next if $pair =~ /^,$/; my ($key, $value) = split /,/, $pair; $hash{$key} = $value; } # do interesting things with one-line %hash here } close HANDLE;
      Bless you Brother!