in reply to Double slashes in regex causing problems

I tried it on 5.8.0 and couldn't reproduce what you're seeing. Could you (a) include a complete standalone script that reproduces the problem, and (b) show the output of perl -V

Thanks, Dave.

  • Comment on Re: Double slashes in regex causing problems

Replies are listed 'Best First'.
Re: Re: Double slashes in regex causing problems
by Anonymous Monk on May 14, 2004 at 14:23 UTC
    This is really strange.

    The code was modifying a value in a hash.
    $$mhash{entries}{$msg}{text} =~ s!http://(.+?)(\s|$)!"\[<a href=\"http +://$1\">Link</a>\]"!ge;

    I change the above to:
    my $string = $$mhash{entries}{$msg}{text}; $string =~ s!http://(.+?)(\s|$)!"\[<a href=\"http://$1\">Link</a>\]"!g +e;

    And it works fine.
      Your initial question didn't mention /g or /e, but your actual example uses both. I'm not sure why you want the /e option here at all.

      However, I've confirmed that (on my 5.6.0 ActiveState build) the deep hash value is not being modified when bound as the lvalue against a s/// operator containing slashes, but it works with a trivial pattern and replacement.

      Update: Duh, a typo. This is working fine for me.

      use strict; use warnings; use Data::Dumper; my $msg = 'a'; my $mhash; $$mhash{entries}{$msg}{text} = "This is a http://foo/bar.html test."; $$mhash{entries}{$msg}{text} =~ s!http://(\S+)![<a href="http://$1" >f +oo</a>]!g; print Dumper $mhash; __OUTPUT__ $VAR1 = { 'entries' => { 'a' => { 'text' => 'This is a [<a href="http://foo/ +bar.html" >foo</a>] test.' } } };
      This sort of pattern is common in blogs and stuff, to find and linkify things that look like URLs. However, you need to be careful about trailing characters that the user has typed as a part of their blog entry. For example, see here (http://perlmonks.org) for a DNS error or here (http://perlmonks.org/index.pl) for a 404 error because of the closing parenthesis characters.

      --
      [ e d @ h a l l e y . c c ]

      In your orignal posting you didn't have the /e on the end of the regex. Do you really want this? And like I said, Could you (a) include a complete standalone script that reproduces the problem, and (b) show the output of perl -V. The script only needs to be 3 lines lines long; just enough to turn the snippets you show above into something I can reproduce here. Dave.