in reply to Re^2: Best way to compare range of characters in two text files
in thread Best way to compare range of characters in two text files

G'day vinoth.ree,

After reading this in your OP:

"... read the first 50 characters ..."

these two lines in your code grabbed my attention:

... my $oshort_line = substr( $oline, 0, 49 ); ... my $nshort_line = substr( $nline, 0, 49 ); ...

I don't know if you thought that's an inclusive range, or something else. See the substr documentation:

"substr EXPR,OFFSET,LENGTH"

To get the first 50 characters from a string, you need OFFSET==0 and LENGTH==50. Here's an example of what you have and one of what you probably want:

$ perl -E 'my $x = "X" x 49 . "Y" x 49; say substr $x, 0, 49' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX $ perl -E 'my $x = "X" x 49 . "Y" x 49; say substr $x, 0, 50' XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXY

— Ken

Replies are listed 'Best First'.
Re^4: Best way to compare range of characters in two text files
by vinoth.ree (Monsignor) on Jul 13, 2018 at 11:37 UTC

    You are right, Actually this script is for other program. I could have posted the other script.


    All is well. I learn by answering your questions...