in reply to Re^2: Use of uninitialized value in substitution iterator in variable expansion
in thread Use of uninitialized value in substitution iterator in variable expansion

Quotation marks. I was suggesting you use quotation marks.
#!perl use strict; use warnings; my $foo = undef; # No warning my $line = 'substitute for $foo in here'; $line =~ s/(\$\w+)/"defined $1 ? $1 : ''"/eeg; print $line, "\n"; # Warning $line = 'substitute for $foo in here'; $line =~ s/(\$\w+)/defined $1 ? $1 : ''/eeg; print $line, "\n";

Caution: Contents may have been coded under pressure.
  • Comment on Re^3: Use of uninitialized value in substitution iterator in variable expansion
  • Download Code

Replies are listed 'Best First'.
Re^4: Use of uninitialized value in substitution iterator in variable expansion
by jaco (Pilgrim) on Apr 07, 2005 at 17:15 UTC

    I understood what you meant, i should have been more clear in my reply. I think i may have discovered part of the problem though. I'll look into it and get back to you

Re^4: Use of uninitialized value in substitution iterator in variable expansion
by jaco (Pilgrim) on Apr 07, 2005 at 17:26 UTC

    It looks like i had a scope problem a little further up in the code. the only reason i noticed it was because i attempted to run your code with the addition on an undelcared var. i.e.

    #!/usr/bin/perl use strict; use warnings; my $foo = undef; # No warning my $line = 'substitute for $foo in $bar here'; $line =~ s/(\$\w+)/"defined $1 ? $1 : ''"/eeg; print $line, "\n";
    hairbear% ./test2.pl Use of uninitialized value in substitution iterator at ./test2.pl line + 11. substitute for in here

    Edit by tye: remove PRE tags around long lines