http://www.perlmonks.org?node_id=951210


in reply to Re^2: Generating a List of numbers
in thread Generating a List of numbers

OK.I'm not advanced enough yet to determine if the solution is for a "different" problem just by looking at the code

The history on this is that I tried getting help with this code(code in my last post) on another thread that fell through the cracks.The code that I initially posted here was the code that I had gotten from that thread. After getting help on here getting it "going", It quickly became apparent that it didn't do what i needed it to do, so I went back to my original question, hoping that your more advanced skills can better help me.

So what I am trying to achieve as demonstrated in my last post(hopefully correctly described) is that for each line within the first loop, I want to loop over the second loop but look for the information that's provided by the first loop upon each pass within the second loop (once this works, then Filtered by a "next if !($Line =~ m/\d*.\d*.\d*.\d*\s*$IpPassedFromTheFirstLoop/);". Weather it's an inner or outer or separate loops, How can I achieve that?

That was my original question on the other thread that took the wrong bend along the way. I now stick with that question.

Thanks,Marc

Replies are listed 'Best First'.
Re^4: Generating a List of numbers
by GrandFather (Saint) on Feb 01, 2012 at 19:56 UTC

    That is a description of how you think you need to write some code to perform some (as yet poorly specified) task. What I want to know is: what is the task you want to perform?

    Most recently it looks like maybe you want to create a file containing a section for each line of an input file where each section contains the line from the input file and the entire contents of a second file. That is completely different than the first question you asked. On top of that the second task seems such an odd thing to want to do (except maybe as an exercise) that I doubt that is what you really want.

    I didn't look (just) at the code to try and figure out what you wanted to do. I looked at the descriptions you gave of two apparently completely different problems. In the first node you say things like "add up the Bytes Field". In the second node you show a block of output that has nothing to do with totalled byte fields. Summing byte fields makes a great deal of sense to me. Creating a file with huge amounts of duplicated data in it makes no sense at all.

    True laziness is hard work
Re^4: Generating a List of numbers
by GrandFather (Saint) on Feb 01, 2012 at 20:06 UTC

    A node which generated 7 replies (not including your own) and to which you replied saying (in part) "Wow, thanks guy's, amazing amounts of posts trying to help me" did not "slip through the cracks".

    Note that you have now described three different problems to be solved. Tell us the bigger picture. Read I know what I mean. Why don't you? then tell us what you actually want to achieve (not how you think it should be done - that has failed three times so far).

    True laziness is hard work
Re^4: Generating a List of numbers
by aaron_baugher (Curate) on Feb 01, 2012 at 23:45 UTC

    You may think you want to have a loop inside a loop, but you really don't. Not with Perl. When a problem sounds like, "I want to look through file1 for records matching strings found in file2," the Perl programmer immediately thinks, "So I put the strings from file2 into a hash as the keys, and then loop through file1 checking to see if each line matches a key in my hash."

    Perl's hashes just make that algorithm so handy that it doesn't make sense to do it with nested loops unless a hash won't work for some reason, which isn't the case here. Or unless your homework assignment says, "Do this with nested loops," in which case you need a new Perl teacher.

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.