regex - Perl: Finding out the unavailable string in a txt file -


I'm starting a new one in Perl, which is using strawberry-pearl,

I A Perl script is written to find special strings in a text file,

===================================

  • Fruit - Banana
  • Fruit - Banana
  • Vegetable - Potato
  • Fruit - Orange
  • Vegetable - Onion
  • Vegetable - Tomato
  • Fruit - Grapes
  • Vegetable - Brinjal
  • Fruit - Strawberry
  • fruit - apricot
  • juice - pineapple
  • Rice - long grains
  • ====================================

    Here's my code,

      #! My @ eatables = ("fruit", "meat", "vegetable"); Open (FH, "& lt; sample.txt") or die "sample can not open txt: $!" ;; Sub head () {while (my $ line = & lt; FH & gt;) {foreach (@Itables) {if ($ line = ~ m / $ _ /) {print "found: $ _ line $. \ N "; }}} Closed (FH); }  Main(); 1;  

    I found the following print,

      found: Line 1 on the fruit was found: found fruit on fruit 2 found: vegetable on line 3 found: fruit Found on line 4: The vegetable was found on line 5: The vegetable was found on line 6: Line 7 on the fruit found: found on the vegetable line 8: Line 9 on the fruit found: fruit 10 on the line  < / Pre> 

    I do not find "found" in my console here: "Print" is required because the sample 'meat' is not available anywhere in the sample. Txt What can I use to make it? Or do I need to modify my search logic? help please.

    Thanks in advance,

    Regards Ramkumar KA

    my @belb = ("fruit", "meat", "vegetable"); Open (FH, "& lt; sample.txt") or die "sample can not open txt: $!" ;; Sub head () {my $ hash = {"fruits" = & gt; 0, "meat" => 0, "vegetable" = & gt; 0}; While (my $ line = & lt; FH & gt;) {foreach (@Itables) {if ($ line = ~ m / $ _ /) {print "found: $ _ line $. $ Hash-> gt; { $ {} $}}} == {$ _} == 0;} Close (FH);} <$ _} ++;}}} Foreach (key% {$ hash}) {print "could not be found: $ _" if $ hash- / Code>

    In this way you can know how many times the epi is in each string.


    Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -