Perl Logic Required

G

Go Perl

Guys,
I am having a problem with implementing a simple logic in Perl. The
following is
a file containing the following numbers..

200 11 36.5
11 12 43.5
12 212 78.9
213 45 56.9
45 46 66.8
46 47 88.0
47 48 89.9
48 49 7.8
49 215 8.9

Now i want to add up all the numbers between (200,212) and (213,215)
and so on.
The numbers i want to add up is the third column for example for
200-212 i want to add 36.5,43.5,78.9. And i want to add up stuff only
if the first column starts with 200 series numbers and the second
column starts with 200 series numbers.

Help Appreciated.
thanks in advance
 
E

Eric Schwartz

I am having a problem with implementing a simple logic in Perl. The
following is a file containing the following numbers..

200 11 36.5
11 12 43.5
12 212 78.9
213 45 56.9
45 46 66.8
46 47 88.0
47 48 89.9
48 49 7.8
49 215 8.9

Now i want to add up all the numbers between (200,212) and (213,215)
and so on.
The numbers i want to add up is the third column for example for
200-212 i want to add 36.5,43.5,78.9. And i want to add up stuff only
if the first column starts with 200 series numbers and the second
column starts with 200 series numbers.

This is very confusing. You really need to stop and think clearly
about what it is you're trying to do, and explain it better. As it
is, from your description, I can only assume you wouldn't add up *ANY*
of the numbers in the third column of the file.

Using my PSI::ESP module, I guess that you have a file which defines a
set of records. Each set starts with a number of the form '2xx' in
the first column. The second column of that row contains the number
in the first column of the next entry in that set. When the number in
second column is of the form '2xx', then the set is over, and you
should record the start and end numbers of the set, and the total of
the numbers in the third column of each entry in the set, and start
over.

But that's only a guess. Please try to be clearer about what you're
asking for.

-=Eric
 
K

Keith Keller

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Using my PSI::ESP module,

Will this module be on CPAN anytime soon? :)

- --keith

- --
(e-mail address removed)-francisco.ca.us
(try just my userid to email me)
alt.os.linux.slackware FAQ: http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj8LPyAACgkQhVcNCxZ5ID87wQCdFYnNN/VdBPUFFSMOH4BDOHOT
ulIAn1ejWQkGHgbWyAMOTVyc88s09Wy/
=Skwa
-----END PGP SIGNATURE-----
 
E

Eric Amick

Guys,
I am having a problem with implementing a simple logic in Perl. The
following is
a file containing the following numbers..

200 11 36.5
11 12 43.5
12 212 78.9
213 45 56.9
45 46 66.8
46 47 88.0
47 48 89.9
48 49 7.8
49 215 8.9

Now i want to add up all the numbers between (200,212) and (213,215)
and so on.
The numbers i want to add up is the third column for example for
200-212 i want to add 36.5,43.5,78.9. And i want to add up stuff only
if the first column starts with 200 series numbers and the second
column starts with 200 series numbers.

I tested with your sample data; it should be extremely close. I assumed
that the values in the first and second columns would never exceed 299.

my ($i, $total, @columns);
while (<>) {
chomp(@columns = split);
if ($i = ($columns[0] >= 200) .. ($columns[1] >= 200)) {
$total += $columns[2];
if ($i =~ /E0$/) {
# end-of-range processing here
$total = 0;
}
}
}

See perldoc perlop, paying particular attention to the range operators.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top