ansh batra has asked for the wisdom of the Perl Monks concerning the following question:

the data i have is

<div class='PlayVideo'></div> A8A <div class='RadioButtonClipStyle'>

what is am doing is
foreach $l(@lines) {#traversing the file if($line=~ /<div class=\'PlayVideo\'><\/div>\n(.*?)/) { $kb_layout_id=$&; print "$kb_layout_id\n"; } }

i want to fetch A8A. can you guyz tell me where i am going wrong?
thanks

Replies are listed 'Best First'.
Re: to get next line of pattern matched
by choroba (Cardinal) on Jan 07, 2013 at 09:39 UTC
    Do not use regular expressions to parse HTML. Use a proper tool. For example, using XML::XSH2, you can load the whole file and extract the string easily:
    open :F html 1011977.html ; echo //div[@class="PlayVideo"]/following-sibling::text() ;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: to get next line of pattern matched
by Anonymous Monk on Jan 07, 2013 at 09:04 UTC

    You're not using quotemeta :)

     my( $lid ) = m{\Q<div class='PlayVideo'></div>\E(.*?)<div class='RadioButtonClipStyle'>}s;

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: to get next line of pattern matched
by 2teez (Vicar) on Jan 07, 2013 at 09:25 UTC

    In a much as I will not recommend using regex to parse HTML doc., however, for this you could use Look-Around Assertions like so:

    use warnings; use strict; my $str = "<div class='PlayVideo'></div> A8A <div class='RadioButtonClipStyle'>"; if ( $str =~ m#(?<=</div>)(.+?)(?=<div.+?>)#s ) { print $1; ## prints A8A }

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      your solution is correct but the file i am parsing contains many div tag
      can you please provide the more specific solution

        Since you're having so many problems achieving this with a regex, have you considered taking the previous advice of using a HTML Parser?