How to read file from specific word in php?

How do I read text file word by word in perl?

  • I want to check 2 words are in same line or not ? how to copy next word from given word in text file ?

  • Answer:

    #!/usr/bin/perl use strict; use warnings; my $filename = $ARGV[0]; my $word1 = "word1"; my $word2 = "word2"; my @words; open( my $fh => $filename) || die "Cannot open $filename: $!"; while(my $line = <$fh>) { @words = split(" ",$line); if (grep (/^$word1$/, @words) && grep (/^$word2$/, @words) ) { print "$word1 and $word2 found in line:$line\n" ; } } close($fh); thanks Tirtha for pointing the mistake in the code, I have updated the code to match the exact words not patterns.

Raghav Yadav at Quora Visit the source

Was this solution helpful to you?

Other answers

Just google for it :)

Akshay Shetye

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.