in reply to Re^4: Changing the numerical value from 0 to 1
in thread Changing the numerical value from 0 to 1
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
|
|---|