in reply to regex match triggers "Use of unititialized value ..." warning

Show us a few lines of your input which trigger the warning message, preferably as a self-contained code sample using __DATA__:
while(<DATA>) { s/(\d),(?=\d)/$1|$2/g; print; } __DATA__

Replies are listed 'Best First'.
Re^2: regex match triggers "Use of unititialized value ..." warning
by mikeraz (Friar) on Feb 22, 2011 at 02:42 UTC

    I didn't include it, as I thought it was trivial..

    #!/usr/bin/perl use strict; use warnings; my $cnt; while(<DATA>) { $cnt++; print "$cnt line\n"; s/(\d),(?=\d)/$1|$2/g; print; } __DATA__ work with 19,43 or so 14,99 we have, at most, 14,23 to do though some say it is 18,44 Without digits, all the , will remain. With digits 9, Ah ha! or With,3 no change for a 2nd line But again 3,4,5,6 all have bars.


    Be Appropriate && Follow Your Curiosity
Re^2: regex match triggers "Use of unititialized value ..." warning
by mikeraz (Friar) on Feb 22, 2011 at 02:44 UTC

    $2 doesn't exist. So that's cleared up now. Thank you. Removing $2 from the code removes the warnings, gives the expected output and all is well.


    Be Appropriate && Follow Your Curiosity