LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-16-2006, 01:46 PM   #1
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Rep: Reputation: 30
Perl! Printing Problem?


Hello and thank you,
So I have posted too much here on LQ for Perl problems but you guys are great so here we go anyway.

My problem is that when I print to a file I get results that 'I' don't think should be there. Oboviously the prgram is doing just what it is told but I cannot figure it out. The main code actually comes from another thread
http://www.linuxquestions.org/questi...d.php?t=410918
I have altered it a bit so that it now takes a list makes the $val from the list.
Code:
while (<MS_file>){
	chomp;
	my ($to_be_peak, $intensity, $FWHM, $res) = split /\t/;
	if ($intensity >= $min){
		$_=$to_be_peak;
		s/(\d+)\.\d+/$1/; # removes the dps
		$peak=$_;
		#$peak = $to_be_peak;
		push(@peak_list, $peak);
	}
}
print MS_out "These results are from : $file\n";
print MS_out "These are the selected peaks\n@peak_list\n";

#---------------------------------------
#the value we want to start with - putting $peak_arrary into $val - and then printing it
for (my $d=0; $d<= @peak_list; $d++){
	$diff_peak[$d]=$peak_list[$d]-$peak_list[$d+1];
}
print "Diff_peak after @diff_peak\n";

for (my $j=0; $j<= @diff_peak;$j++){
	$val=$diff_peak[$j];
#	$val = 89; #test 
	print "This is val $val\n"; # test value
	&find_molecules($val, 0, \%a_result, $accuracy); # start function with new val
	#to print the results on your screen
	foreach my $rh_result(@list_of_results){
		foreach(keys %{$rh_result}){
			print MS_out ($_, "\t", $rh_result->{$_}, "\n");
		}
		print MS_out "*******************\n";
	}
	print MS_out "_________________End_of_Result_________________\n";
	foreach my $rh_result (@list_of_results){
		foreach (keys %{$rh_result}){
			$rh_result->{$_}=0;
		}
	}
}
print MS_out "/\/\/\ \n";
#--------------------------------------
#Now find the difference and find possiblitiess
sub find_molecules{
	my ($current_val, $current_index, $rh_result, $acc)= @_;
	#we go through all the element_masses, which weren't below equal or below zero before
	for(my $i=$current_index; $i<=$#element_masses; $i++){
		#if the current_val is equal the current element_mass
		if(!($current_val-$element_masses[$i])){
			#we add the result to the list_of_results
			my %a_result= %{$rh_result};
			$a_result{$element_masses[$i]}++;
			push @list_of_results, \%a_result;
			#if the difference is greater than zero, we keep on going
		}elsif($current_val-$element_masses[$i] >= $acc){
			my %a_result= %{$rh_result};
			#we add the current element_mass to the result hash
			$a_result{$element_masses[$i]}++;
			#and call ourselves with the new parameters..
			&find_molecules($current_val-$element_masses[$i], $i, \%a_result, $acc);
		}
	}
}
So the file print out looks like this (Wow this is going to be long sorry )
Code:
These results are from : Proline.txt
These are the selected peaks
117 116 71 70
1	1
16	0              # Normal!
12	0
14	0
*******************
_________________End_of_Result_________________
1	1
16	0              # Why does it do this?
12	0
14	0
*******************
1	1
16	2
12	1
14	0
*******************
1	13
16	2
12	0
14	0
*******************
1	1
16	1
12	0
14	2
*******************
A lot more file....
*******************
1	21
16	0
12	2
14	0
*******************
1	33
16	0
12	1
14	0
*******************
1	45
16	0
12	0
14	0
*******************
_________________End_of_Result_________________
1	1
16	0                   #Why does it do this?
12	0
14	0
*******************
1	1
16	2
12	1
14	0
*******************
So the file goes on further with more of the mistakes noted in the file.

Cheers,


PB
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl - printing progress on same line. Technoslave Programming 7 09-03-2011 09:20 PM
printing Spanish accent characters in Perl/tk entry widget puedo Programming 1 02-19-2005 01:16 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
Perl - printing features satimis Programming 6 11-14-2004 11:45 AM
perl printing pantera Programming 1 06-02-2004 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration