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

Ah, you changed your requirements.

You get what you ask for, we're not mindreaders. How are we supposed to figure out what you really want when you don't give examples?

You never did mention file sizes, did you?

  • Comment on Re^3: Finding the parent of a text in a file

Replies are listed 'Best First'.
Re^4: Finding the parent of a text in a file
by ExperimentsWithPerl (Acolyte) on Sep 05, 2015 at 20:59 UTC
    #!/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"}, } );
      { 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"