Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Compressing a text file using count of continous characters

by oha (Friar)
on Dec 14, 2007 at 17:00 UTC ( #657080=note: print w/replies, xml ) Need Help??


in reply to Compressing a text file using count of continous characters

s/((\D)\2+)/length($1).$2/ge;
it search for a non-number, then search if it's repeated 1 or more times, then replace it by the count of them followed by the the repeated char
Oha

PS: could be usefull to limit the number of repeated matches, and include the numbers. but in this case numbers must always have a counter:

s/((\D)\2{1,8}|(\d)\3{0,8})/length($1).$2.$3/ge;
this one will compare 2 or more char, or 1 or more if digit and match no more then a sequence of 9.
in this way you can decode the data with no side-effect if strange data is used: X2AAAAAAAAAAAAAAAAAAAAAAA1111 become X129A9A5A41
A repetitions are grouped up to a max of 9, numbers are counted as repetition also if not repeated.
to decode use:
s/(\d)(.)/$2x$1/ge;

Oha

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-01-19 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?