RSS Forums RSS

split and assign values in a file.

Please support our Perl advertiser: Programming Forums
Thread Solved
Reply
Posts: 3
Reputation: aanya is an unknown quantity at this point 
Solved Threads: 0
aanya aanya is offline Offline
Newbie Poster

split and assign values in a file.

  #1  
Oct 7th, 2008
Iam new to perl. This is my problem.
I have calculated the distance using the formula

my $distance = sqrt(($x2 - $x1)**2 + ($y2 - $y1)**2 + ($z2 - $z1)**2);
and the value of $distance looks like this:

3.72851967944384
5.83210433720111
7.12922562414741
10.2322964186931
11.2073015931579
11.882666956538
14.4465118281196
16.0581479006765
17.2278339903773

Now I have to open a file that looks like this:

1 3.90
2 4.90
3 4.91
4 5.12
.
.
.
71 50.23
72 51.00
.
.
180 78.00

I have opened this file

open(DIST,"path/DBins.pl") or die "$!";
while(my $lines = <DIST>){
chomp($lines);
my @point = (split (/\s+/, $lines))[1,2];

I have to compare the value of $distance (shown above)with the above file with the second column and print out the corresponding first column value. the threshold value is 71(1st column). Any value of $distance above 50.00 should stop there and retrieve the first column values of 50.23. The first column is the index value and second column(floating point values) is the energy values.

Till now I have split the line in the file, but i dnt know how to assign values to that array to the two columns . I dont know how to compare the value of $distance to the second column and get the corresponding first column values as output.
Please help.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 843
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 63
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: split and assign values in a file.

  #2  
Oct 7th, 2008
You have this posted on too many forums for me to want to help you. You should also try and do your own school work.
Reply With Quote  
Posts: 5,133
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 634
Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: split and assign values in a file.

  #3  
Oct 7th, 2008
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
Reply With Quote  
Posts: 843
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 63
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: split and assign values in a file.

  #4  
Oct 7th, 2008
And the same person on tek-tips, and perlguru, and daniweb, and ??
Reply With Quote  
Posts: 3
Reputation: aanya is an unknown quantity at this point 
Solved Threads: 0
aanya aanya is offline Offline
Newbie Poster

Re: split and assign values in a file.

  #5  
Oct 7th, 2008
yes Kevin, I had posted to another forum, as I tried to solve it and i am stuck, i am still learning perl and i was stuck upto splitting the array, not knowing how to assign values to that. I know the algorithm, but i find it very difficult to write the syntax.
Reply With Quote  
Posts: 3
Reputation: aanya is an unknown quantity at this point 
Solved Threads: 0
aanya aanya is offline Offline
Newbie Poster

Re: split and assign values in a file.

  #6  
Oct 7th, 2008
Originally Posted by Salem View Post
Is this you as well?
http://www.daniweb.com/forums/thread148485.html


No, thats not me. !!!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 1130 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:38 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC