If you find word boundaries a bit hard to rely on (ie, like me, probably don't understand all the possible implications) you probably should use the more robust regex (Kenosis's 2nd example]) to dodge the bullet in some of the cases in this code (Updated to include both of Kenosis' other suggestions):
#!/usr/bin/perl use 5.016; use warnings; # 1071410 change ONLY numbers which are (one digit only) 0 my @arr = qw(20 14 007 0 1203 '' 7900130 43.02 0.03 0.0 ); for my $elem(@arr) { if ( $elem=~ /^0{1}$/ ){ say $elem; my $elem1 = $elem =~ s/^0{1}$/1/; say $elem1; } } say "above, results from Ln1-14; below: Kenosis' 3: \n"; my @arr3 = qw(20 14 007 0 1203 '' 7900130 43.02 0.03 0.0 ); for (@arr3) { print "Original \@arr3 element: |$_| becomes (or remains as) "; $_ = 1 if $_ == 0; say $_; } say "\n Kenosis' 1 (boundary version): "; my @arr1 = qw(20 14 007 0 1203 '' 7900130 43.02 0.03 0.0 ); for (@arr1) { s/\b0\b/1/; print "Original \@arr1 element: |$_| becomes (or remains as) "; say $_; }

Execution:

C:\> 1071410.pl 0 1 above, results from Ln1-14; below: Kenosis' 3: Original @arr3 element: |20| becomes (or remains as) 20 Original @arr3 element: |14| becomes (or remains as) 14 Original @arr3 element: |007| becomes (or remains as) 007 Original @arr3 element: |0| becomes (or remains as) 1 Original @arr3 element: |1203| becomes (or remains as) 1203 Argument "''" isn't numeric in numeric eq (==) at 1071410.pl line 20. Original @arr3 element: |''| becomes (or remains as) 1 Original @arr3 element: |7900130| becomes (or remains as) 7900130 Original @arr3 element: |43.02| becomes (or remains as) 43.02 Original @arr3 element: |0.03| becomes (or remains as) 0.03 Original @arr3 element: |0.0| becomes (or remains as) 1 Kenosis' 1 (boundary version): Original @arr1 element: |20| becomes (or remains as) 20 Original @arr1 element: |14| becomes (or remains as) 14 Original @arr1 element: |007| becomes (or remains as) 007 Original @arr1 element: |1| becomes (or remains as) 1 Original @arr1 element: |1203| becomes (or remains as) 1203 Original @arr1 element: |''| becomes (or remains as) '' Original @arr1 element: |7900130| becomes (or remains as) 7900130 Original @arr1 element: |43.02| becomes (or remains as) 43.02 Original @arr1 element: |1.03| becomes (or remains as) 1.03 Original @arr1 element: |1.0| becomes (or remains as) 1.0

Anchoring a single zero -- as in the match and the substitution above -- seems to me the clearest way of ensuring you substitute only when the spreadsheet cells holds ONLY a single zero.

CAUTIONARY NOTE: I have not tested this with data from a spreadsheet utilizing formatted color, etc) data... and it still seems likely to fail if the column is formatted with leading zeros or a fixed number of fractional (decimalized) values (for example, if "1/2" were presented as ".50" by formatting the cell to require 2 digits after the decimal point but without requiring a leading "0" before the point).

Come, let us reason together: Spirit of the Monastery

In reply to Re: Changing the numerical value from 0 to 1 by ww
in thread Changing the numerical value from 0 to 1 by hellohello1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.