in reply to Re: I need your opinion on pushing two columns into an array
in thread I need your opinion on pushing two columns into an array

Thanks. What I'm try to do is search a text file for certain numbers and if it finds it in the array to replace it. The problem I'm now having is in my if statement. The $stmt_tr keeps on changing to the array variable when it should keep the number I'm trying to find in the array.
while (<CIPA>) { my $string = $_; my $stmt_tr = substr($_,126,10); if ((substr($string,126,1) =~ m/5/) && (substr($string,98,8) = +~ m/20081112/)) { foreach my $x (@trace_row) { if ($stmt_tr = $x->{trace_orig}) { print $x->{trace_orig} . "\n"; } } print $string; ++$rcount; print $rcount . "\n"; } }

Replies are listed 'Best First'.
Re^3: I need your opinion on pushing two columns into an array
by ccn (Vicar) on Nov 16, 2008 at 17:26 UTC
    if ($stmt_tr = $x->{trace_orig}) { is an assigment

    use
    if ($stmt_tr == $x->{trace_orig}) { 'double =' for numbers
    if ($stmt_tr eq $x->{trace_orig}) { 'eq' for strings

Re^3: I need your opinion on pushing two columns into an array
by jwkrahn (Abbot) on Nov 16, 2008 at 22:46 UTC
    while (<CIPA>) { my $string = $_; my $stmt_tr = substr($_,126,10); if ((substr($string,126,1) =~ m/5/) && (substr($string,98,8) = +~ m/20081112/)) {

    That should be:

    while ( my $string = <CIPA> ) { my $stmt_tr = substr $string, 126, 10; if ( substr( $string, 126, 1 ) == 5 && substr( $string, 98, 8 +) == 20081112 ) {
Re^3: I need your opinion on pushing two columns into an array
by drodinthe559 (Monk) on Nov 16, 2008 at 17:36 UTC
    I found the cheesy mistake that is make that happen "=". I should be using "=~".