Hi All,

I appologies ahead of time if this might seem a bit confusing since it is confusing to me.. feel free to ask for clarifications if i didn't explain myself properly!

So basically, I have a list of numbers (called "NumbersList") which looks like this:

This is a numbers List 10 23432 20 23424 60 45567 20 56756 30 91857 50 29349 10 93729 80 82374 20 82757 30 92785 50 71674 70 81747 20 83758 30 89275 10 19594 60 09214 20 09347 50 83725 90 91845 20 76402 30 90184 The numbers should appear as random

Out of this list of numbers I need to pick out the lines that match the numbers that are inside the next list (called "LookingForTheseNumbersList"). This list looks like this:

20 30 50

The end result of what I am trying to achieve would be a list that would be like this: (printed output)

20 23424 20 56756 20 82757 20 83758 20 09347 20 76402 30 91857 30 92785 30 89275 30 90184 50 29349 50 71674 50 83725

Now beware that the printed output is simply what i would see on the screen. upon each loop passes, I need to run calculations on each "sections" of numbers. for example, the "20" section, I will need to add up all the numbers to the right of them and print the results, then proceed to adding up all the numbers for the "30" section, so on so forth...

I know I am close but for the life of me, I can't figure out how to make it work...This is what the code that does all the work looks like:

#!/usr/bin/perl -w use strict; my $FALSE = 0; my $TRUE = 1; my $Flag = $TRUE; my $NumbersList = "<" . "NumbersList"; my $LookingForTheseNumbersList = "<" . "LookingForTheseNumbersList" +; open NUMBERSLIST, "NumbersList" or die $!; open LOOKINGFORTHESENUMBERSLIST, "LookingForTheseNumbersList" or die $ +!; if ($Flag == $TRUE) { foreach my $Line (<NUMBERSLIST>) { #print "Numbers list number = : $Line"; &FlagEqualsTrue($Line); } } sub FlagEqualsTrue { (my $LookingForNumber) = @_; foreach my $Line (<LOOKINGFORTHESENUMBERSLIST>) { chomp $Line; next if ($Line =~ m/^These/); next if ($Line =~ m/^This/); next if !($Line =~ m/^$LookingForNumber/); print "$Line\n"; } } exit;

Maybe I am approaching this wrong but I am not advanced in perl enough yet to be able to tell.. any thoughts?

Thanks, M


In reply to Generating a list of numbers from other lists by mlebel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.