there is a csv file like this:
date, val1, val2, val3, val4 etc
1/2/2007, 1, 4, 5, 6
1/3/2007, 2, 5, 7, 10
1/5/2007, 5, 6, 8, 11
what I need to do is, calculate the differnce between cells for each column and write it to a file. for example, since there is no previous value to row one, write first row to a file. then subtrack second raw values from the first row values and write the output to the second line in ouptput file - (2-1, 5-4, 7-5, 10, 6). Third raw in the output file should be, 5-2, 6-5, 8-7, 11-10 and so on. Can anybody help me with this?
7 2040
Please post what you have tried so far.
I dont even know how to start this
Well, if that is the case, I would have to ask how much Perl experience do you have? Do you know how to work with modules?
I am asking because there is a perl module that falls under the DBI module family called DBD::CSV, that allows you to interact with a CSV file as if it were a database. Take a read of that page to find out about it.
If you don't have much Perl experience, I would definitely run down to your local Barnes & Noble and pick up "Learning Perl, 4th Edition" as it is a great starter book.
Regards,
Jeff
I have little experience with perl. I was thinking about making an array, read the lines into an array and try to subtrack the numbers like that but it may need to be two dimensional arrays.
-
#!/usr/local/bin/perl
-
-
use Data::Dumper;
-
-
open(FILE,"<test.csv");
-
$row=-1;$col=-1;
-
while (<FILE>) {
-
chomp;
-
if (/^[0-9]/) {
-
chomp;
-
$row++;
-
$col = -1;
-
-
foreach $char (split /,/) {
-
$col++;
-
$cell[$row][$col]=$char;
-
}
-
}
-
}
-
-
for $i (0..$#cell) {
-
$aref = $cell[$i];
-
$n = @$aref - 1;
-
for $j (0..$n) {
-
print "$cell[$i][$j],";
-
}
-
print "\n";
-
}
-
basically, I have the information in the two dimensional array now. what I need to do is to the subtrack the symetic cells from each other. First column is the time stamp and needs to be left alone.
there is a csv file like this:
date, val1, val2, val3, val4 etc
1/2/2007, 1, 4, 5, 6
1/3/2007, 2, 5, 7, 10
1/5/2007, 5, 6, 8, 11
what I need to do is, calculate the differnce between cells for each column and write it to a file. for example, since there is no previous value to row one, write first row to a file. then subtrack second raw values from the first row values and write the output to the second line in ouptput file - (2-1, 5-4, 7-5, 10, 6). Third raw in the output file should be, 5-2, 6-5, 8-7, 11-10 and so on. Can anybody help me with this?
I have this code so far. -
#!/usr/local/bin/perl
-
use Data::Dumper;
-
open(FILE,"<test.csv");
-
-
$row=-1;$col=-1;
-
while (<FILE>) {
-
chomp;
-
if (/^[0-9]/) {
-
chomp;
-
$row++;
-
$col = -1;
-
foreach $char (split /,/) {
-
$col++;
-
$cell[$row][$col]=$char;
-
}
-
}
-
}
-
-
for $i (0..$#cell) {
-
$aref = $cell[$i];
-
$n = @$aref - 1;
-
for $j (0..$n) {
-
print "$cell[$i][$j],";
-
}
-
print "\n";
-
}
-
Please do not double post your question. I've merged the two threads for you.
- MODERATOR
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Job Lot |
last post by:
I have to create a loan (Line of Credit) tracker application, where users can analyse their loan over a term. They can make changes to monthly entries to see how long it would take them to pay of the...
|
by: Mika |
last post by:
Is it possible to perform functions on a recordset (rather than on the
source database), e.g. COUNT, MAX etc
The reason I would like to do this is because I have a hugely complex view
which...
|
by: mrid via DotNetMonster.com |
last post by:
hi. im exporting data from a vb form to excel. i am able to create a new
excel file, save and edit it without any trouble, but the formatting is
giving me hell! i need to be able to show certain...
|
by: murdock |
last post by:
Is there a way to perform functions upon databound data that is to be
used in a GridView? For example, in the following code where I am using
a GridView to display a resulting asp:SqlDataSource
...
|
by: acecraig100 |
last post by:
I am fairly new to Javascript. I have a form that users fill out to
enter an animal to exhibit at a fair. Because we have no way of
knowing, how many animals a user may enter, I created a table...
|
by: Bails |
last post by:
Hi, Im in the process of building my VERY first VB .Net Express app in
the form of a Poker Tournament timer.
I have the basics up and running ( thanks Tom), but want to add some
extra features....
|
by: wrldruler |
last post by:
Hello,
First, I know it's against "Access Law" to save calculations in a
table, but....I want/need to.
I currently have sub-totals being calculated inside a form, using
DMax, DCount, and...
|
by: Catalyst159 |
last post by:
I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows:
Part A: Maximum FAR and Floor Area:
Part B: Gross Floor Area of...
|
by: Blacky |
last post by:
Hi,
I am using c# asp.net application.I have datagrid which binds column dynamically and i make certain columns say visibility to false in my itemdatabound event EMPID AS E.ITEM.CELLS.VISIBLE =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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: 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...
| |