I want to get all the numbers out of a file that looks like this
1,2
4,3,2
and have the first number point to an array of the others in a hash
I'm almost able to do this except for the fact that a '\n'
get ad to the last number,
I'm trying to get rid of it but somehow chomp just won't work
code :
Expand|Select|Wrap|Line Numbers
- open (DataBase,"voorwaardelijk.txt");
- my @data = <DataBase>;
- foreach my $voorwaarde (@data)
- {
- chomp $voorwaarde;
- # split de lijn op in de getallen verdeeld door een komma en steek ze in een array
- my @getallen = split(/,/,$voorwaarde);
- print @getallen;
- # het eerste element in de voorwaarde is de ziekte die de voorwaarde nodig heeft, we gebruiken deze als key, en verwijderen deze ook uit de array
- my $key = shift(@getallen);
- # steek de array in de hash
- $voorwaardehash{$key} = [@getallen];
- }