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

push @trace_rw, [unpack 'A10A8', $_] while <TRACE>;

or

my @trace_rw = map { [unpack 'A10A8', $_] } <TRACE>;

Replies are listed 'Best First'.
Re^2: I need your opinion on pushing two columns into an array
by drodinthe559 (Monk) on Nov 16, 2008 at 17:20 UTC
    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"; } }
      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

      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 ) {
      I found the cheesy mistake that is make that happen "=". I should be using "=~".