Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl Logic Required

Reply
Thread Tools

Perl Logic Required

 
 
Go Perl
Guest
Posts: n/a
 
      07-08-2003
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
 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      07-08-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Go Perl) writes:
> 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
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Reply With Quote
 
 
 
 
Keith Keller
Guest
Posts: n/a
 
      07-08-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <(E-Mail Removed)>, Eric Schwartz wrote:
>
> Using my PSI::ESP module,


Will this module be on CPAN anytime soon?

- --keith

- --
http://www.velocityreviews.com/forums/(E-Mail 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-----
 
Reply With Quote
 
Bob Dover
Guest
Posts: n/a
 
      07-08-2003
"Go Perl" wrote...
>
> I am having a problem with implementing a simple logic in Perl.


Care to show us what you've tried?

-BD


 
Reply With Quote
 
Eric Amick
Guest
Posts: n/a
 
      07-08-2003
On 8 Jul 2003 13:41:35 -0700, (E-Mail Removed) (Go Perl) wrote:

>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.

--
Eric Amick
Columbia, MD
 
Reply With Quote
 
Helgi Briem
Guest
Posts: n/a
 
      07-09-2003
On Tue, 8 Jul 2003 15:01:05 -0700, Keith Keller
<(E-Mail Removed)-francisco.ca.us> wrote:

>In article <(E-Mail Removed)>, Eric Schwartz wrote:
>>
>> Using my PSI::ESP module,

>
>Will this module be on CPAN anytime soon?


It's always been there, but you need to be
psychic to find out where.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Logic Map/Logic Flow Chart. (Example Provided) spike Python 8 02-09-2010 12:31 PM
Asynchronous Logic Gates and Analog Logic Gates Jyoti Ballabh Software 3 11-26-2009 06:48 PM
logic, algorithms, and (Perl) data structures ccc31807 Perl Misc 4 03-26-2009 10:32 PM
Create a VD with required properties on a required Web Server (Windows Advanced Server 2000 has 3 Web Servers) Just D. ASP .Net 0 03-10-2006 06:02 AM
Perl Project Logic Question Tyler Cruz Perl Misc 1 08-01-2003 03:32 PM



Advertisments