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

Hello Anonymous Monk, Apologies for the inconvenience.
I was about to respond to you but Couldn't login today due to Wifi issues.
Is there any way I can send attachments here because the code and examples are looking really messy when I am pasting it here.
If there is no way to send attachment then I will the code anyhow.
Again I would mention that I am new to this language, and have no intention to insult the monks who are helping me.

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

Replies are listed 'Best First'.
Re^5: Finding the parent of a text in a file
by AnomalousMonk (Archbishop) on Sep 05, 2015 at 22:10 UTC
    Is there any way I can send attachments ...

    I don't know about attachments per se, but you do have a public scratchpad where you can post something temporarily for viewing or pickup by others. However, it's public, so if you don't want it potentially seen by all and sundry, best find another way. (You also have a private scratchpad, but I think that's for you alone; you cannot grant access unless you give someone your password, allowing them to sign on as you.) I say the scratchpads are "temporary," but I don't really know the policy on this. I do know I've had some stuff on my scratchpads for quite a while and it's never been touched by the PsTB, nor has there ever been any suggestion about any sort of cleanup. Of course, if you start posting mega- or gigabytes of stuff, you may attract the attention of janitors (see What do Janitors do?) or even Gods!


    Give a man a fish:  <%-{-{-{-<

      Please find below the modified code :-
      #!/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"}, } );
Re^5: Finding the parent of a text in a file
by Anonymous Monk on Sep 05, 2015 at 23:51 UTC

    Answers needed:

    1) how large are your input files (in lines)?

    2) What OS are you running on?

    3) Are your input files always the same length (in lines)? With only some words changed? Or with whole new lines added?


      1) how large are your input files (in lines)?
      Ans : 13000 lines

      What OS are you running on?
      Ans : Sun Solaris and Linux

      Are your input files always the same length (in lines)? With only some words changed? Or with whole new lines added?
      Ans: The number of inputs lines and their contents vary depends on platform.

        #!/usr/bin/perl # http://perlmonks.org/?node_id=1140982 use strict; use warnings; my $filenameone = '1.pc.d'; # change to your main filename my $filenametwo = '2.pc.d'; # change to your secondary filename my @parents; # should work on linux, not sure what Solaris diff args are... open my $fh, '-|', "diff -U 999 $filenametwo $filenameone" or die $!; scalar <$fh>; # ignore first scalar <$fh>; # two lines while(<$fh>) { s/^([ +])(?=( *))// or next; $#parents = length($2) - 1; # truncate array push @parents, $_; $1 eq ' ' and next; defined and print, $_ = undef for @parents; }

        If this doesn't work, please give a small test case that shows the failure.