Connecting Tech Pros Worldwide Forums | Help | Site Map

problem with chomp

Newbie
 
Join Date: Dec 2007
Posts: 7
#1: Dec 22 '07
I'm having this weird problem with chomp
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
  1. open (DataBase,"voorwaardelijk.txt");
  2.  
  3.     my @data = <DataBase>;
  4.  
  5.     foreach my $voorwaarde (@data)
  6.     {
  7.  
  8.         chomp $voorwaarde;
  9.  
  10.         # split de lijn op in de getallen verdeeld door een komma en steek ze in een array
  11.         my @getallen = split(/,/,$voorwaarde);
  12.  
  13.         print @getallen;
  14.  
  15.         # 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
  16.         my $key = shift(@getallen);
  17.  
  18.         # steek de array in de hash
  19.  
  20.         $voorwaardehash{$key} = [@getallen];
  21.  
  22.     }
the last line of numbers in the file doesn't have a '\n' so that's why I'm trying to use chomp.

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Dec 22 '07

re: problem with chomp


You have several threads open to which you have not replied. I will personally not help you until you reply to the threads you already have open. You should also not open a new thread if the question relates very closely to your open threads, which this one appears to do. Continuing in your old thread makes it easier to review all the previous suggestions and any sample data you may have posted.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,572
#3: Dec 22 '07

re: problem with chomp


I back Kevin up whole heartedly! You need to provide answers to your other threads to which there are questions waiting.

Kevin,

If the other threads are all along the same line, then send me the links to all the threads and I will merge them into one.

Regards,

Jeff
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#4: Dec 23 '07

re: problem with chomp


attach the data file to a post, very hard to say what is happening without seeing your data file. Perl will not add a newline. The only time I know of when perl adds a newline is when compiled with the -L switch, but that only affects printing to STDOUT if I remember correctly.
Reply