in reply to Match/Replace/Interpolate

I'd do the whole search-and-replace thing in one step instead of two steps:

$line =~ s!<gid=(\d+)>!<img src="PATH/TO/$1">!g;

I think the only problem with your approach is that it lacked the /g "global" modifier that replaces all occurrences within one line.

20060721 shmem spotted a missing > sign, thanks!

Replies are listed 'Best First'.
Re^2: Match/Replace/Interpolate
by toadi (Chaplain) on Jul 21, 2006 at 08:58 UTC
    Hi Corion, thanks for the reply. What do the ! mean instead of the normal / in the regex?


    --
    My opinions may have changed,
    but not the fact that I am right

      The ! are used as alternative delimiters, because you use / within the regular expression. This makes it easy to avoid the escaping of slashes. Instead of \/, I now can write / as it will not be recognized as the regex delimiter anymore.

      perlop has the section on Regexp Quote-like Operators which explains how this works.

      They don't mean anything special, you can replace the '/' with any other character (or matching pairs of brackets) to improve readability and reduce the requirement for escaping of literal '/' characters in your expression.

      /J\