Dear JohnGG

Thank you very much for your prompt reply! I really appreciate it! I did run into some small problems because my computer did not recognize the code(had many errors). After some research I found out that this is because I using windows (I feel even more beginner now for not figuring that out), but as a result I had some difficulties understanding the code because I am used to a completely different way of writing code(some lines are still difficult for me to understand, but I get what you're doing)

Could you maybe check whether this 'translation' is correct, because when I replace the first line by using strict and warnings it provides me with 2 errors later in the code

$ perl -Mstrict -Mwarnings -E ; my $wordsFH = "woord.txt"; open(INPUT, $wordsFH) or die "Cannot open $filename"; my %words = map {chomp; $_ => 0 } <INPUT>; my $rxWords = do { local $" = q{ | }; qr{(?x) \b ( @{ [ keys %words ] } ) \b }; }; print "Regex is $rxWords"; my $textFH = "4.txt"; open (texting, $textFH) or die; my $text = do { local $/; <texting>; }; $words{$1} ++ while $text =~ m{$rxWords}g; print "$_ => $words{ $_ }}" for sort keys %words;

Furhtermore, I still have 2 problems that I need to tackle and of which I am not sure how to handle them. 1 Is it possible to extract the total number of 'hits'? $total ++ while $text =~ m{$rxWords}g; works, but may I incorporate it so that I do not have to use the regex twice. 2 Is there a simple addition to calculate the total number of words? (is setting up an array with chop the easiest solution?)

Again, thank you so much for your time!


In reply to Re^2: count number of overlapping words in a document by dmarcel
in thread count number of overlapping words in a document by dmarcel

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.