Perl Logic Required

Discussion in 'Perl Misc' started by Go Perl, Jul 8, 2003.

  1. Go Perl

    Go Perl Guest

    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
    Go Perl, Jul 8, 2003
    #1
    1. Advertising

  2. (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.
    Eric Schwartz, Jul 8, 2003
    #2
    1. Advertising

  3. Go Perl

    Keith Keller Guest

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

    In article <>, Eric Schwartz wrote:
    >
    > Using my PSI::ESP module,


    Will this module be on CPAN anytime soon? :)

    - --keith

    - --
    -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-----
    Keith Keller, Jul 8, 2003
    #3
  4. Go Perl

    Bob Dover Guest

    "Go Perl" wrote...
    >
    > I am having a problem with implementing a simple logic in Perl.


    Care to show us what you've tried?

    -BD
    Bob Dover, Jul 8, 2003
    #4
  5. Go Perl

    Eric Amick Guest

    On 8 Jul 2003 13:41:35 -0700, (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
    Eric Amick, Jul 8, 2003
    #5
  6. Go Perl

    Helgi Briem Guest

    On Tue, 8 Jul 2003 15:01:05 -0700, Keith Keller
    <-francisco.ca.us> wrote:

    >In article <>, 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.
    Helgi Briem, Jul 9, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,767
  2. Just D.
    Replies:
    0
    Views:
    436
    Just D.
    Mar 10, 2006
  3. spike
    Replies:
    8
    Views:
    1,438
    Steve Holden
    Feb 9, 2010
  4. Tyler Cruz

    Perl Project Logic Question

    Tyler Cruz, Jul 31, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    66
    Tyler Cruz
    Aug 1, 2003
  5. ccc31807
    Replies:
    4
    Views:
    157
    smallpond
    Mar 26, 2009
Loading...

Share This Page