in reply to Re^2: Grabbing url from iframe
in thread Grabbing url from iframe

The approach is fundamentally bad. You're using split, but you don't have a separated list of things to split on.

Either option you choose, you need to

  1. Parse the HTML
  2. Locate the elements
  3. Modify the elements
  4. Regenerate the HTML

In this case, that can all be done by one substitution.

s/ (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) / $1 . "320" . $3 . ( (320/$2)*$4 ) . $5 /xeg

Replies are listed 'Best First'.
Re^4: Grabbing url from iframe
by htmanning (Friar) on Feb 12, 2011 at 19:51 UTC
    Thanks for this. Here's what I have:
    $video =~ s/ (<iframe [ ]title="YouTube[ ]video[ ]player" [ ]width=")([0-9]+)(" [ ]height=")([0-9]+)(" ) / $1 . "320" . $3 . ( (320/$2)*$4 ) . $5 /xeg;
    But it's returning this error:
    Scalar found where operator expected at mobile.pl line 296, near "$1 . + "320" . $3 . ( (320/$2" (Might be a runaway multi-line // string starting on line 289) (Missing operator before $2?) syntax error at mobile.pl line 296, near "$1 . "320" . $3 . ( (320/$2"
    Am I missing something?

      You delimit your regular expression using /, but the replacement part also contains a /. That's unfortunate. Use a different separator for the regular expression, for example !:

      $video =~ s!... !... !xeg;
        You're exactly right. That did it. Thanks so much. This was over my head but that worked! Can someone explain what this last line does. I sort of get it, but not really.
        $1 . "300" . $3 . ((300/$2)*$4) . $5