Your LWP stuff looks fine, but you need to make a few changes to your regular expression syntax to change to make this work. Should get you started, but there's plenty of good documentation about using regular expressions about.
  1. you need to use the pattern-match operator =~, not just a plain = to match a $string; ie:
    $string =~ m/
  2. You need to capture something using the * modifier between the start and end of the comment you're looking for. A * just tells Perl to get as much 'something' (where something is the thing preceding the *) as possible. To get as much of anything as possible, use .* ie:
    $string =~ m/($start)(.*)($end)/
  3. The page that's coming back runs over lots of lines. By default, Perl only matches over one line to find a pattern. Use the /s modifier at the end of your regular expression to tell Perl to search over newline boundaries. ie:
    $string =~ m/($start)(.*)($end)/s
  4. Since the target webpage has got lots of pairs of matched comments, and because .* is 'greedy' (it takes as much stuff as possible while still matching a pattern), you'll get everything between the *first* $start and the *last* end. That's loads of stuff. Use the ? (non-greedy) modifier on .* to get just the first result item. ie:
    $string =~ m/($start)(.*?)($end)/s
  5. You don't need to put brackets around $start and $end, because in your programme, you already know what's in there. Brackets capture the stuff that's matched between them and save them, which you don't want to do. ie:
    $string =~ m/$start(.*?)$end/s $result = $1;
A

In reply to Re: pattern matching by ViceRaid
in thread pattern matching by silent11

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.