Your problem is almost certainly this line:

$outputb = "\t$resultarray[3]";

$outputb does not equal $resultarray[3]; it equals a TAB ('\t') followed by $resultarray[3].

Here's some examples of the types of tests you could have run to check this yourself:

#!/usr/bin/env perl -l use strict; use warnings; my @resultarray; my $outputb; $resultarray[3] = 0; $outputb = "\t$resultarray[3]"; print '$resultarray[3] = |', $resultarray[3], '|'; print '$outputb = |', $outputb, '|'; check_for_match_zero('$resultarray[3]', $resultarray[3]); check_for_match_zero('$outputb', $outputb); sub check_for_match_zero { my ($name, $value) = @_; if ($value =~ /^0$/) { print "$name (with value: '$value') MATCHES zero."; } else { print "$name (with value: '$value') DOES NOT MATCH zero."; } }

Output:

$resultarray[3] = |0| $outputb = | 0| $resultarray[3] (with value: '0') MATCHES zero. $outputb (with value: ' 0') DOES NOT MATCH zero.

[I see ++AnomalousMonk has shown you how to do the substitution on just one element (i.e. $resultarray[3]) as requested.]

-- Ken


In reply to Re^5: Changing the numerical value from 0 to 1 by kcott
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.