473,480 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with chomp

7 New Member
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.
Dec 22 '07 #1
3 1963
KevinADC
4,059 Recognized Expert Specialist
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.
Dec 22 '07 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
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
Dec 22 '07 #3
KevinADC
4,059 Recognized Expert Specialist
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.
Dec 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5328
by: Matt Taylor | last post by:
I have this piece of code: $/ = ' '; $test = "abc "; chomp $test; print $test; which prints spaces at the end of the line. Shouldn't chomp strip the spaces off the end of my scalar $test?
3
2873
by: Mothra | last post by:
Here's what I'm trying to do (kill off old Unix logins): --------------------- $i=0; while (<$who>) { chomp($_); my @line = split(/\s+/, $_); # Split it into an array next unless ($line...
2
15564
by: perl_begi | last post by:
I am having a file that contains different strings, which in turn are name of folders. For example test. file has: test0002 intel/drivers/ Here there can be spaces, tabs after folder names...
35
19400
by: lnatz | last post by:
Hi, Is there an equivalent to the perl command chomp in C? And if there is no exact equivalent command, how would I go about removing the "\n" at the end of a stdin? Thank you, Natalie
2
2325
diamond1
by: diamond1 | last post by:
Hi I have a problem with the Foreign key in Postgres 8.1 under Windows XP for example: I have PERSON table as a superclass and PERSON_A, PERSON_B, PERSON_C as subclasses Table_X as an...
2
1356
by: itzaps | last post by:
Hi, I want to write a perl script that will take value from an external file the file will be in name=value format and write those values to another file My problem is I am not able to select...
5
2641
by: Beany | last post by:
Hi, Probably a very simple question for the experienced Perl programmers.... Im new to the language of Perl and at the moment im studying the function Chomp! for some strange reason i cant...
3
4006
by: kumarboston | last post by:
Hi All, I have two tables of data, one contains 9 columns and another has 7 columns, both the tables has 3 column common, now what i am trying to do is to merge the two tables in one using hash....
4
1870
by: ezechiel | last post by:
Hi, while testing the program (runs in DOS), I thought "if someone hits enter without typing a letter before, what happens?" I tested and the script ends.. Is this normal, or how can I avoid this?...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.