in reply to Re^2: Multiple strings in a file
in thread Multiple strings in a file

> Is that more clear?

no because your code should already do this, if you don't want double matches follow toolic's advice.

Cheers Rolf

PS: Je suis Charlie!

Replies are listed 'Best First'.
Re^4: Multiple strings in a file
by The_Last_Monk (Novice) on Feb 10, 2015 at 18:05 UTC
    I did, the problem that i am having testing locally is that it doesn't seem to recognize that there are more than 2 lines. So if the word i want is within the first 2 lines, it will print it, but if i want to print a word from the 3rd line, it won't

      Hi,

      Let see this code,

      use strict; use warnings; my $firstString='Trap'; my $secondString='hair'; open my $text, "<test.txt" or die "Dead"; while(<$text>){ print if (m/($firstString|$secondString)/i) }
      file:
      Transformers robots in disguise
      I whip my hair back and forth
      I will catch a dog with a trap

      It prints the output as,

      I whip my hair back and forth
      I will catch a dog with a trap
      

      But as you want to match the 'Trap' first which is in the third line, should be printed first and 'Hair' should be printed next. Is that you wanted?


      All is well
        Yes, that is exactly what i wanted!