in reply to Determine new line number in revised file given old line number

#!/usr/bin/perl # http://perlmonks.org/?node_id=1186417 use strict; use warnings; use Algorithm::Diff qw(traverse_sequences); my @one = do { local @ARGV = $ARGV[0]; <> }; my @two = do { local @ARGV = $ARGV[1]; <> }; my $wantedoldline = $ARGV[2]; my $oldline = my $newline = 0; traverse_sequences( \@one, \@two, { MATCH => sub { $oldline++; $newline++; if( $oldline == $wantedoldline ) { print "$newline\n"; exit; } }, DISCARD_A => sub { $oldline++ }, DISCARD_B => sub { $newline++ }, } ); print "0\n";
  • Comment on Re: Determine new line number in revised file given old line number
  • Download Code

Replies are listed 'Best First'.
Re^2: Determine new line number in revised file given old line number
by shmem (Chancellor) on Mar 29, 2017 at 22:02 UTC

    For me it is amazing how you always present clear, succinct solutions to given problems without much ado. Without teaching, you teach. Learn from this code, which is pushing the bar in the threads context.

    Please stay a while with us, we could learn so much from you.

    I fancy a node called "Zen, perlgolf and the art of coding"... ah well.

    Big thanks, tybalt89++

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'