in reply to match substitution

I tried the following back reference:
use utf8; my $str = "725-275 is an entry - and will be at 423-569 -but- not at 0 +12-457."; $str =~ s/(\d{3})-(\d{3})/\1\_\2/g; print "$str\n"
which produced the following result:
725_275 is an entry - and will be at 423_569 -but- not at 012_457.

I am getting some strange characters if I use \x{2014}! I am not sure about the hyphen to dash substitution. Update: I just saw ikegami's reply!

Replies are listed 'Best First'.
Re^2: match substitution
by ikegami (Patriarch) on Jan 27, 2010 at 00:42 UTC
    Actually, it produces
    \1 better written as $1 at a.pl line 3. \2 better written as $2 at a.pl line 3. 725_275 is an entry - and will be at 423_569 -but- not at 012_457.
    if you don't disable warnings. \1 and \2 are not a valid Perl variables.
      Thanks for pointing it out. You are right, I get the same when I turn the warnings on!
      UPDATE:
      use strict; use warnings; #use utf8; my $str = "725-275 is an entry - and will be at 423-569 -but- not at 0 +12-457."; print "before: $str\n"; $str =~ s/([0-9]{3})-([0-9]{3})/$1\x{2014}$2/g; print "after: $str\n" produces: before: 725-275 is an entry - and will be at 423-569 -but- not at 012- +457. after: 725—275 is an entry - and will be at 423—569 -but- not at 012—4 +57.
        Wow! Thanks!