Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Calculated position incorrect when using regex in text file that also contains binary info

by geertvc (Sexton)
on Jun 17, 2020 at 05:35 UTC ( #11118166=note: print w/replies, xml ) Need Help??


in reply to Re: Calculated position incorrect when using regex in text file that also contains binary info
in thread Calculated position incorrect when using regex in text file that also contains binary info

Hello hippo,

I just tried your code on a Windows 10 machine and here it fails. Result:

1..8 ok 1 - No 1 first match starts at 26 ok 2 - No 1 first match ends at 33 ok 3 - No 2 first match starts at 68 ok 4 - No 2 first match ends at 75 ok 5 - No 3 first match starts at 87 ok 6 - No 3 first match ends at 94 not ok 7 - No 4 first match starts at 1315 # Failed test 'No 4 first match starts at 1315' # at E:\AppData\Programming\Perl\ReadFile/hippo.pl line 50. # got: '1139' # expected: '1315' not ok 8 - No 4 first match ends at 1322 # Failed test 'No 4 first match ends at 1322' # at E:\AppData\Programming\Perl\ReadFile/hippo.pl line 51. # got: '1146' # expected: '1322'
Even the "got" values (calculated based on the Windows OS) are not correct when checking the location of the items in a text editor (I'm using NPP as text editor) in Windows. It should be 923 and 930 for the 4th object (as opposed to 1139 and 1146 in your script result).

So, "a" conclusion might be that Windows (once again) differs from Linux in the way files are handled.

Would there be a need to open the file with a specific encoding?

Best,
Geert
  • Comment on Re^2: Calculated position incorrect when using regex in text file that also contains binary info
  • Download Code

Replies are listed 'Best First'.
Re^3: Calculated position incorrect when using regex in text file that also contains binary info on MSWin
by hippo (Bishop) on Jun 17, 2020 at 08:20 UTC
    So, "a" conclusion might be that Windows (once again) differs from Linux in the way files are handled.

    Quite probably. Having no recent experience of MS Windows I'm not in a position to help you further, unfortunately. In your shoes I would try to persist with the SSCCE, however. The fact that it currently fails shows the problem in isolation which might help to solve it. Good luck.

Re^3: Calculated position incorrect when using regex in text file that also contains binary info
by Anonymous Monk on Jun 19, 2020 at 02:29 UTC

    Hi

    The proper way to share binary data inside perl programs is to use Data::Dump::dd()

    This is especially true if you share that file on the internet

    Without this you have no basis for any conclusions

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118166]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2021-10-18 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (72 votes). Check out past polls.

    Notices?