We don't bite newbies here... much PerlMonks

Re^2: Generating a List of numbers

by GrandFather (Sage)
 on Feb 01, 2012 at 04:16 UTC ( #951115=note: print w/replies, xml ) Need Help??

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

What you have shown (ignoring the bugs - there are some) is a solution to a different problem than the one you initially asked for help with! To avoid wasting our time helping you solve a problem that doesn't actually help you, what are you really trying to do?

The short answer to "if so what?" is that your inner loop runs to the end of its file so the second time through the outer loop there is nothing left for the inner loop to loop over. However the code you show is bad in too many ways for me to bother with until I know I'm not wasting my time solving non-problems aside from saying "don't nest loops that read from files - it's almost always wrong".

True laziness is hard work

Replies are listed 'Best First'.
Re^3: Generating a List of numbers
by mlebel (Hermit) on Feb 01, 2012 at 13:09 UTC

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

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

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

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.

Create A New User
Node Status?
node history
Node Type: note [id://951115]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-04-23 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (85 votes). Check out past polls.

Notices?