By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,777 Members | 1,755 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,777 IT Pros & Developers. It's quick & easy.

parsing pipe delimited txt file

P: 14
Hi All,

In file1.txt I have following data.


All the data are pipe delimited. The first field is questions(id) and second field is answer(id).
Now I want if questions ids are same like 2nd line and 3rd line then all of its answers id should be appended like following....


I have the following code....
Expand|Select|Wrap|Line Numbers
  1. my %ques_row = ();
  2. my @army;
  3. my $i = 0;
  4. open (FH, "<file.txt") or die "Cannot open remove_duplicate file for reading: $!";
  5. while (my $each_row = <FH> ) {
  6. chomp($each_row);
  7.     my @row = split(/\|/, $each_row);
  8.     $ques_row{$row[0]}[$i] = $row[1];
  9.     $i++;
  10. }
  11. close FH;
With this code the problem is when it is placing all answers in hashes of array, then it will put the empty element as $i is increasing by one. So how to remove all the empty elements from the array.

Please help me to correct my logic or code.

Aug 29 '08 #1
Share this Question
Share on Google+
1 Reply

P: 14

I made it work using different way. Sorry to bother.

Aug 29 '08 #2

Post your reply

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