in reply to Re: 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?
Or if you are doing something with the hash line-by-line: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
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: How can I read a line of text from a file into an array?
by fenners (Beadle) on Jul 19, 2001 at 00:04 UTC |