in reply to Re^3: Finding the parent of a text in a file
in thread Finding the parent of a text in a file

#!/usr/bin/perl # http://perlmonks.org/?node_id=1140982 use Algorithm::Diff qw(traverse_sequences); #use strict; #use warnings; open (FH , "<123") or die $!; open (FH2 , "<456") or die $!; my @file1 = <FH>; my @file2 = <FH2>; sub fullpath { my @full; my @answer; for my $line ( shift() =~ /.+\n/g ) { $line =~ /^( *)/; $#full = length($1) - 1; # truncate array push @full, $line; push @answer, join '', grep defined, @full; } return \@answer; } print @file1; print @file2; my $len1 = scalar(@file1); print "len1 : $len1\n"; my $len2 = scalar(@file2); print "len2 : $len2\n"; for (my $i==0 ; $i < $len1 ; $i++) { for (my $j==0 ; $j < $len1 ; $j++) { if ($i==$j) { my $line1 = $file1[i]; my $line2 = $file2[j]; my $full1 = fullpath($line1); my $full2 = fullpath($line2); } } } traverse_sequences( $full1, $full2, { # DISCARD_A => sub {print $full1->[shift()], "\n"}, } );

Replies are listed 'Best First'.
Re^5: Finding the parent of a text in a file
by Anonymous Monk on Sep 05, 2015 at 23:36 UTC
    { my $line1 = $file1[i]; my $line2 = $file2[j]; my $full1 = fullpath($line1); my $full2 = fullpath($line2); }

    "my"s are local to the enclosing block - these six lines do nothing.

    Please *never* comment out "use strict" and "use warnings"