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

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

Replies are listed 'Best First'.
Re^4: creating an index of files contents
by nirelit (Initiate) on Sep 23, 2016 at 13:03 UTC
    thank you very much, my reply was edited, since as you suggested, was misleading, and drove to confusion...