Angie Ahl wrote:
>
> I'm trying to get the value of $1 into a var, the following don't work
> and I can't figure out why
>
>     $_ = $html_body;
>     my ($resrow) = m#<!-- VM: resrow -->(.*?)<!-- VM: /resrow -->#;
>                    m#<!-- VM: resrow -->(.*?)<!-- VM: /resrow -->#;
>     #print $1;
>     print $resrow;
>
> $resrow holds nothing, however if I print $1 I do have a match
>
>     $_ = $html_body;
>     m#<!-- VM: resrow -->(.*?)<!-- VM: /resrow -->#;
>     my $resrow = $1;
>     print $resrow;
>
> doesn't work either.
>
> How do I get $1 into a var for later use. It's driving me a little loopy
> now.
>
> I'm basically trying to extract the middle bit into a var of it's own. I
> thought that would be easy....

Hi Angie.

It looks like your regex isn't matching. $1 will keep the value captured by
the last successful match.

Try this code. (The 'for ($html_body) { .. }' aliases $_ with $html_body
for the extent of the code block.)

  my $resrow;

  for ($html_body) {
    if (m#<!-- VM: resrow -->(.*?)<!-- VM: /resrow -->#) {
      $resrow = $1;
    }
    else {
      die "No match for HTML";
    }
  }

  print $resrow, "\n";

So I guess you need to fix your regex. Is it possible that the actual
text contains a newline? In which case you need to replace spaces with
'\s+'.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to