LanX has asked for the wisdom of the Perl Monks concerning the following question:
lets say I wanted a sliding window to search a file from end to start.²
Could do this with seek and read in a loop.
Now is seek operating on byte boundaries ,but read depends on the encryption layer. °
What's the best way than to read an encoded file, like in UTF-8, backwards ?
Is read fail-proof when accidentally starting inside a wide character after a seek?
Or is it better to open :raw and to search the next character (or line) boundary manually and to decode with Encode then?
I'm aware of File::ReadBackwards , but want to understand the mechanisms better and operate on windows and not lines.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
DB<1> open $fh,'<','input2' DB<2> read $fh => $in, 100 DB<3> p tell $fh 114 # surprise DB<4> open $fh,'<:raw','input2' DB<5> p tell $fh 0 DB<6> read $fh => $in, 100 DB<7> p tell $fh 100 DB<8>
²) I've been asked what I mean with "sliding window", please see this sliding window description. There I start from the beginning, but it's often favorable to start from the end. (choroba++ for pm'ing me)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Processing an encoded file backwards
by haukex (Archbishop) on Jan 18, 2020 at 20:23 UTC | |
by LanX (Saint) on Jan 18, 2020 at 20:41 UTC | |
by haukex (Archbishop) on Jan 18, 2020 at 20:56 UTC | |
by LanX (Saint) on Jan 18, 2020 at 21:16 UTC | |
by haukex (Archbishop) on Jan 18, 2020 at 21:53 UTC | |
| |
|
Re: Processing an encoded file backwards
by LanX (Saint) on Jan 18, 2020 at 20:30 UTC |