mlebel has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|