in reply to Re: creating an index of files contents
in thread creating an index of files contents

thank you for your quick reply, an example with code would be also much appreciated

Update:
thank you for your quick reply, a more detailed description on your approach with the reverse index would be also much appreciated

  • Comment on Re^2: creating an index of files contents

Replies are listed 'Best First'.
Re^3: creating an index of files contents
by haukex (Archbishop) on Sep 23, 2016 at 10:35 UTC

    Hi nirelit,

    You'll find some example code under the links I provided and by searching for the names of the modules (one example of many). Note that your request for "example with code" can be (mis)understood to mean "please do my work for me for free", which is considered rude. A good rule of thumb is that people will expend roughly as much effort answering a question as the person asking the question put into it; personally I'm quite happy to provide code for those who have shown their efforts. My suggestion is that you try writing some code, and if you have trouble with it please feel free to post here (guidelines on good questions) and I'm sure people will be happy to help more.

    Regards,
    -- Hauke D

Re^3: creating an index of files contents
by haukex (Archbishop) on Sep 23, 2016 at 12:24 UTC

    Hi nirelit,

    a more detailed description on your approach with the reverse index would be also much appreciated

    Please mark updates to your nodes as such. See How do I change/delete my post?, especially "It is uncool to update a node in a way that renders replies confusing or meaningless".

    Anyway, I'll give you the following hint: as you're reading your input files, let's say you have the current directory name stored in the variable $curdir, and you're reading your input file line-by-line (see for example "Files and I/O" in perlintro). Then you could do something like this:

    my %reversetbl; # at the beginning # ... open each file ... while (<$fh>) { chomp; # remove newline # ... $reversetbl{$_}{$curdir}++; } # at the end: for my $k (keys %reversetbl) { print $k, ';', join(',', keys %{ $reversetbl{$k} } ), "\n"; }

    This will give you the "6576576;dir1,dir2" output you want.

    To see what this code is doing, you can look at the data structure (a "hash of hashes") with Data::Dumper, for example: use Data::Dumper; print Dumper(\%reversetbl);.

    Hope this helps,
    -- Hauke D

      thank you very much, my reply was edited, since as you suggested, was misleading, and drove to confusion...