in reply to How to remove non-numbers from string

numify the string, $string += 0;
  • Comment on Re: How to remove non-numbers from string

Replies are listed 'Best First'.
Re^2: How to remove non-numbers from string
by AnomalousMonk (Archbishop) on Jun 21, 2015 at 20:46 UTC

    Problematic with warnings enabled:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $string = 'data.csv'; $string =~ s/\D//g; $string += 0; print qq{'$string'}; " Argument "" isn't numeric in addition (+) at -e line 1. '0'


    Give a man a fish:  <%-(-(-(-<

      Yes, I have just encountered this very same problem!
Re^2: How to remove non-numbers from string
by kgherman (Novice) on Jun 21, 2015 at 20:43 UTC
    Great idea; thank you!