http://en.wikipedia.org/wiki/Run-length_encoding (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the original run. This is most useful on data that contains many such runs: for example, relatively simple graphic images such as icons, line drawings, and animations. It is not recommended for use with files that don't have many runs as it could potentially double the file size. For example, consider a screen containing plain black text on a solid white background. There will be many long runs of white pixels in the blank space, and many short runs of black pixels within the text. Let us take a hypothetical single scan line, with B representing a black pixel and W representing white: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW If we apply the run-length encoding (RLE) data compression algorithm to the above hypothetical scan line, we get the following: 12W1B12W3B24W1B14W Interpret this as twelve W's, one B, twelve W's, three B's, etc. While: WBWBWBWBWBWBWB would be: 1W1B1W1B1W1B1W1B1W1B1W1B1W1B The encoding data is quite longer. -------------------------------------------------------------------------------- Write a program that takes a command (encode or decode) an input file and an output file and either encodes or decodes (to/from RLE) the file. perl rle.pl encode input.txt output.txt perl rle.pl decode encoded.txt original.txt