473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Printing first column value

Hi All,

I have data file which has 6 column, I am trying to take the first value(-16.2577) of 6th column and substract it to the rest of the values of 6th column.
I split the file on space and stored in an array but the problem is I am not able to pick the first value and substract it in while loop.

DATA FILE:
-16.2262 -6.01803 -25.5829 -19.4488 -14.0128 -16.2577
-18.6505 -23.0397 -26.0685 -24.5328 -21.9307 -22.8444
-30.1621 -22.6838 -17.0961 -17.0979 -16.7653 -20.761
-21.5754 -21.2215 -13.6387 -12.3095 -17.8838 -17.3258
-21.7664 -25.4331 -22.6777 -23.1687 -24.755 -23.5602
-16.739 -13.0645 -28.5916 -19.7581 -24.1668 -20.464
-15.3542 -21.8463 -24.1616 -33.7034 -22.4266 -23.4984
-17.021 -22.1811 -23.1971 -11.4303 -29.3547 -20.6368
-25.7525 -15.5314 -20.4551 -19.9354 -26.7343 -21.6817
-12.4969 -9.64406 -23.1891 -18.2173 -18.8544 -16.4804
-22.9877 -26.167 -25.5358 -10.8135 -19.1759 -20.936
-17.3839 -14.6625 -12.1523 -16.8928 -28.1319 -17.8447
-14.5102 -15.1774 -21.9974 -24.3167 -27.1646 -20.6333
-12.6622 -17.8959 -17.2385 -17.1209 -18.1484 -16.6132
-23.6795 -23.24 -24.8987 -13.5031 -27.6614 -22.5965
-19.0322 -14.2305 -26.3313 -19.6006 -28.2886 -21.4966
-20.5431 -7.20871 -21.5272 -14.0325 -24.7013 -17.6026
-20.7694 -13.2671 -29.6587 -16.5918 -19.0846 -19.8743
-12.4844 -10.0744 -23.2201 -21.8157 -21.002 -17.7193
-20.9622 -15.8527 -22.7274 -28.2274 -28.6891 -23.2918
-24.8432 -11.8968 -24.58 -18.6088 -22.4424 -20.4742


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. open(A,"rot_1.dat");
  6. while (<A>)
  7. {
  8.     my @temp = split(/\s+/,$_);
  9.     my $a = $temp[5];
  10.     $a = $a - (-16.277);
  11.     print "$a\n";
  12. }
  13.  
Any help will be appriciated.

Thanks
Kumarboston
Oct 26 '09 #1
1 3563
toolic
70 Expert
Try something like this:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $first_val;
  5. open my $fh, '<', 'rot_1.dat' or die "can not open rot_1.dat: $!";
  6. while (<$fh>) {
  7.     my $col6 = (split)[5];
  8.     $first_val = $col6 if $. == 1;  # first line
  9.     print $col6 - $first_val, "\n";
  10. }
  11.  
  12. __END__
  13. 0.0
  14. -6.5867
  15. -4.5033
  16. -1.0681
  17. -7.3025
  18. -4.2063
  19. -7.2407
  20. -4.3791
  21. -5.424
  22. -0.2227
  23. -4.6783
  24. -1.587
  25. -4.3756
  26. -0.355499999999999
  27. -6.3388
  28. -5.2389
  29. -1.3449
  30. -3.6166
  31. -1.4616
  32. -7.0341
  33. -4.2165
  34.  
To control the precision of your output, use printf.
Oct 27 '09 #2

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

Similar topics

10
by: Mario | last post by:
Hello all, I'm trying hard to make possible to print some simple text from python to the default printer using wxPython, after days of internet searches I found this page:...
0
by: Bob Greschke | last post by:
Howdy! I have a Python/MySQL program that produces HTML pages from some items in our inventory database. These pages are varying numbers of 1-row, 3-column tables whose first column is a...
2
by: DBQueen | last post by:
I have a database which will be printing out labels for SMALL test tubes (1/4" high). We have yet to find a reasonably-priced printer (labelwriter) which can effectively print this on ROLLS of...
1
by: ManuelC | last post by:
Hi I have a form that contains a multiselect listbox (simple multiselect) and a command button. The listbox shows a list of all reports (about 20) available for users to print and the command...
1
by: JackM | last post by:
I'm not sure if this qualifies as a mysql or a php question so I'm asking in both groups. I am pulling the results of a mysql query from my database and want to print the results into a two...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Any tips on how to print the data in a datagridview control?
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
13
by: Umesh | last post by:
I was just wondering how to print two strings coulmnwise. char string1="abcd"; char string2="efgh"; now i want to print something like this: a e b f c g
0
by: GiftX | last post by:
VB 6.0 And Spreadsheet - Printing problem Good morning West. After much research, I found this code. It scans the spreadsheet and returns up to the last used cell. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.