Easy way to replace 0 with empty string?

A

Andreas Kahari

Is there an easy one line way to replace a 0 with empty string?

Do you need anything more sofisticated than "s/0//"?


$ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
1
 
D

David K. Wall

Andreas Kahari said:
Do you need anything more sofisticated than "s/0//"?


$ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
1

If it's just a single character I'd use 'tr/0//d'.

I'm not entirely sure what is meant by "empty string". It might
possibly mean replacing '0' with a space: 'tr/0/ /'.
 
A

Anno Siegel

Andreas Kahari said:
Do you need anything more sofisticated than "s/0//"?


$ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
1

The OP has under-specified his problem. What he wants may also be the
common idiom "$x ||= ''". It replaces 0 (and undef) with an empty string.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top