Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

First of all, while I don't know in this case if this is homework, the way your post is written sounds like some homework-like questions I have seen before. Most people here have already done their share of homework, and so may be a little reluctant to do someone else's as well. Show what you've tried so far, or even how you think you might, and you will likely get more/better results in the future. That having been said, now back to our regularly-scheduled post.

If the search list is short enough, you can store the items as keys in a hash, then loop thru general data file and push the line numbers into the hash when found, and when done list the entries found. Something like the following (untested) code might work...

open(SF, $searchfile) or die(qq{Can't open $searchfile for input: $!\n}); while (<SF>) { chomp; @{$results{$_}} = (); } close(SF); open(DF, $datafile) or die(qq{Can't open $datafile for input: $!\n}); while (<DF>) { foreach my $k (keys %results) { if (m/$k/) { push(@{$results{$k}}, $.); last; } } } close(DF); foreach my $k (sort keys %results) { if (scalar @{$results{$k}}) { printf "%s:\n\t%s\n", $k, join(",", sort @{$results{$k}}); } }

Hope that helps.


In reply to Re: compare two text files by atcroft
in thread compare two text files by juergenkemeter

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2023-01-30 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?