![]() |
|
Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Extract Block Of Text From Logby cavac (Curate) |
on Nov 21, 2018 at 06:58 UTC ( #1226107=note: print w/replies, xml ) | Need Help?? |
Well, i'd use a classic state machine for this problem, then we can work line-by-line, without having to load the whole file into memory.
That way, we can even modify the program very slightly to make it work via pipes, working live on a stream of data generated by some other program. We just remove the open and close calls and change the while loop a bit:
Then we can use the program on an arbitrary stream of this kind of data, and it extracts each block as soon as it is pushed into the programs STDIN:
And the only thing the state machine has to hold in memory is the block it is currently working on and a single state variable...
perl -e 'use MIME::Base64; print decode_base64("4pmsIE5ldmVyIGdvbm5hIGdpdmUgeW91IHVwCiAgTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duLi4uIOKZqwo=");'
In Section
Seekers of Perl Wisdom
|
|