in reply to Mixed script and binary problems to extract with susbstr

print $fh substr($fc, $start, $numbers[$i]) ;

The @numbers array seems to be a sequence of start positions (offsets), but substr has the syntax
    substr EXPR,OFFSET,LENGTH
so perhaps
    print $fh substr($fc, $start, $numbers[$i]) ;
needs to be (untested)
    print $fh substr($fc, $start, $numbers[$i] - $start) ;
in the posted loop code.

(This assumes you've got your file read-writes properly binmode-ed now.)

Update: Minor changes (update: and a link added) for clarity.


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

Replies are listed 'Best First'.
Re^2: Mixed script and binary problems to extract with susbstr
by Veltro (Hermit) on Feb 15, 2021 at 21:15 UTC

    Thank you (and thanks to the Anonymous Monk as well). I was so focused on the binary that I did not think of checking the arguments of substr. It works fine now.