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

I'm confused. The code you post in Re^3: Use of uninitialized value in concatenation is essentially identical to the code I posted in Re^2: Use of uninitialized value in concatenation. I agree that instead of printing 'dollarfoo' as you require, it prints 'dollar', but I get no warnings at all.

Can you please post the exact code you are executing and the execution output so I can see the exact warning message? (This is only to satisfy my curiosity; there is no urgency.)

Replies are listed 'Best First'.
Re^5: Use of uninitialized value in concatenation
by Anonymous Monk on Jun 12, 2009 at 04:08 UTC
    #!/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.
      Again, the following code, using a regex from postings elsewhere in this thread, always perfectly defines  $2 (although sometimes it is defined as the empty string – perfectly valid!) and seems to give the required output:
      >perl -wMstrict -le "my %words = map { $_ => 1 } qw($Word $name $test); my $line = '$Word $ $ $ $test $testing'; $line =~ s/(\$(\w*))/exists $words{$1} ? $1 : qq{dollar$2}/eg; print qq{$line}; " $Word dollar dollar dollar $test dollartesting
      Note that  (\$(\w*)) is the regex used.