kgherman has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
If I have a string in perl, say 'data12.csv', I know I can remove the nun-numbers by using
#!/usr/bin/perl my $string=('data12.csv'); $string=~ s/\D//g; print "$string\n";
which returns 12. However, when I get a string 'data.csv' the previous lines of code return, not surprisingly, nothing. How can I tell perl to return, in such case, 0?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to remove non-numbers from string
by Laurent_R (Canon) on Jun 21, 2015 at 20:39 UTC | |
by AnomalousMonk (Archbishop) on Jun 21, 2015 at 20:47 UTC | |
by kgherman (Novice) on Jun 21, 2015 at 20:44 UTC | |
|
Re: How to remove non-numbers from string
by stevieb (Canon) on Jun 21, 2015 at 20:52 UTC | |
|
Re: How to remove non-numbers from string
by ww (Archbishop) on Jun 21, 2015 at 21:09 UTC | |
by ww (Archbishop) on Jun 22, 2015 at 13:48 UTC | |
|
Re: How to remove non-numbers from string
by Anonymous Monk on Jun 21, 2015 at 20:39 UTC | |
by AnomalousMonk (Archbishop) on Jun 21, 2015 at 20:46 UTC | |
by kgherman (Novice) on Jun 21, 2015 at 21:32 UTC | |
by kgherman (Novice) on Jun 21, 2015 at 20:43 UTC |