Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^4: Parse txt file into array of array

by Dr Manhattan (Beadle)
on Jun 07, 2013 at 07:55 UTC ( #1037615=note: print w/replies, xml ) Need Help??

in reply to Re^3: Parse txt file into array of array
in thread Parse txt file into array of array

Ohke, so I now have this

open (A1, "<An1.txt") or die "can't open"; open (A2, "<An2.txt") or die "can't open"; my @array1; my @array2; while (<A1>) { my $in = $_; chomp $in; push (@array1, [split(//, $in)]); } while (<A2>) { my $in = $_; chomp $in; push (@array2, [split(//, $in)]); } my $length = $#array1; my $total = 0; for (my $x = 0; $x <= $length; $x++) + { my $smallLength = scalar(@{$array1[$x]}); for(my $q = 0; $q <= $smallLength; $q++) { if($array1[$x][$q] =~ /^(\+|\_)$/ && $array2[$x][$q] =~ /^[A-Z +a-z]$/) { splice(@{$array2[$x]}, $q, 0, ''); } if($array2[$x][$q] =~ /^(\+|\_)$/ && $array1[$x][$q] =~ /^[A-Z +a-z]$/) { + splice(@{$array1[$x]}, $q, 0, ''); } $total++; } }

I am trying to compare and calculate the diffence between to text files. Calculations come later in my code but that is not important. I get error message 'Use of uninitialized value in pattern match (m//)' for the 2 IF statements. Any idea why?

Replies are listed 'Best First'.
Re^5: Parse txt file into array of array
by kcott (Canon) on Jun 07, 2013 at 09:48 UTC

    Firstly, this is veering completely off-topic. Further, the default depth for viewing threads is Re^3 so most won't even view this new question. Start a new thread when you have a new question - you can always add a link to a previous thread if it has supporting information.

    You have an off-by-one error. An array of 10 elements has indices in the range 0 to 9. In the outer loop, you're checking the correct range with 0 to $#array1; in the inner loop you're checking past the end of the array: 0 to scalar(@{$array1[$x]}).

    -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037615]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2017-03-25 06:38 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (311 votes). Check out past polls.