in reply to Re: Use of uninitialized value in concatenation
in thread Use of uninitialized value in concatenation

>perl -wMstrict -le "my %words = map { $_ => 1 } qw($Word $name); my $line = '$Word $ $foo'; $line =~ s/(\$\w*)/exists $words{$1} ? $1 : qq{ dollar }/eg; print $line; " $Word dollar dollar
I think the OPer wants '$foo' to be replaced by 'dollarfoo'. And what's with the extra spaces?

Replies are listed 'Best First'.
Re^3: Use of uninitialized value in concatenation
by gem555 (Acolyte) on Jun 11, 2009 at 11:20 UTC
    #!/usr/bin/perl -w use strict; my %words = map { $_ => 1 } qw($Word $name); my $line = '$Word $ $foo'; $line =~ s/(\$\w*)/exists $words{$1} ? $1 : qq{ dollar }/eg; print $line;
    For $foo it prints dollar and not dollarfoo. But still gets a warning message
        #!/usr/bin/perl -w use strict; use warnings; my %words = map { $_ => 1 } qw($Word $name $test); my $line = '$Word $ $ $ $test $testing'; $line =~ s/(\$(\w+)*)/exists $words{$1} ? $1 : "dollar$2"/eg; print "$line\n\n";
        The exact code I am using is this. When I execute this : output is
        Use of uninitialized value in concatenation (.) or string at ex.pl lin +e 6. Use of uninitialized value in concatenation (.) or string at ex.pl lin +e 6. Use of uninitialized value in concatenation (.) or string at ex.pl lin +e 6. $Word dollar dollar dollar $test dollartesting
        The problem is with "$2". How to define $2.