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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|