in reply to Searching a pattern's first and last occurrence in a file.

a single huge line of 1000s of words

Slurp the file and use index, rindex and substr:

my $content = do{ local @ARGV = 'theFile.htm'; <> }; my $first = index $content, 'Oct-18-2013'; my $last = rindex $content, 'Oct-18-2013'; print substr $content, $first, $last;;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Searching a pattern's first and last occurrence in a file.
by ankurk (Initiate) on Oct 19, 2013 at 17:05 UTC

    Thanks a lot i am almost done now. Just wanted to ask is there any way to search a file for a string bottom up? I know there is a module file::readbackwards,But i am not able to install it. any other way?

    Secondly how do i search ABCXXX where xxx could be Jan Feb...... Dec

    Thanks

    Ankur

      is there any way to search a file for a string bottom up?

      There are ways, but unless your file(s) are so big that you cannot fit them in memory(?), I wouldn't bother because they are horribly inefficient.

      Secondly how do i search ABCXXX where xxx could be Jan Feb...... Dec

      Use regex.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Actually i need to search html tag like <XXX>Jan or <XXX>Feb ... and so on. Not getting the desired results.
        Thanks for your help... Took me some time to troubleshoot. But finally getting the required results.

        Cheers

        Ankur