Easy way to replace 0 with empty string?

Discussion in 'Perl Misc' started by Paul Tomlinson, Sep 25, 2003.

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

    PT
     
    Paul Tomlinson, Sep 25, 2003
    #1
    1. Advertisements

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


    $ perl -e '$a=10; $a =~ s/0//;print $a, "\n"'
    1
     
    Andreas Kahari, Sep 25, 2003
    #2
    1. Advertisements

  3. 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/ /'.
     
    David K. Wall, Sep 25, 2003
    #3
  4. Paul Tomlinson

    Anno Siegel Guest

    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
     
    Anno Siegel, Sep 25, 2003
    #4
  5. $input =~ tr/0//d;
     
    Steve Grazzini, Sep 25, 2003
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.