No such thing as a small change PerlMonks

### Re: Determine new line number in revised file given old line number

by tybalt89 (Prior)
 on Mar 29, 2017 at 19:55 UTC ( #1186430=note: print w/replies, xml ) Need Help??

```#!/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

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'

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1186430]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-01-19 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2022, my preferred method to securely store passwords is:

Results (56 votes). Check out past polls.

Notices?