RE: Трава перл...фсем курить;-)

Skachkov Eugene e_skachkov на diamond.ru
Сб Сен 27 18:37:41 CDT 2003


#!/usr/bin/perl

use strict;
my $text = qq`A simple, easy to remember system for encoding integer amounts can be very
useful. For example, dealers at flea markets put the information about an item
on a card that they let potential buyers see. They find it advantageous to
encode the amount they originally paid for the item on the card.\nA good system
is to use a substitution code, in which each digit is encoded by a letter. An
easy to remember 10-letter word or phrase, the key, is chosen. Every '1' in the
value is replaced by the first letter of the key, every '2' is replaced by the
second letter of the key, and so on. Every '0' is replaced by the last letter of
the key. Letters that do not appear in the key can be inserted anywhere without
affecting the value represented by the code.. This helps to make the resulting
code much harder to break (without knowing the key).\nCreate a class Substitute
that contains the method getValue that is given the Strings key and code as
input and that returns the decoded value.`;
my $point = $ARGV[0];

$text =~ s/\n/ /g;
$text =~ s/\s+/ /g;

while ( $text =~ s/^(.{1,$point})[ |.](.*)$/$2/ )
{
    my (@words,$length);
    my $remainder = $point - ( length($1) );
    $length = @words = split (' ', $1);
    my $isidenumber = 0;
    for (0 .. $remainder)
    {
        $words[$isidenumber++] .= ' ';
        $isidenumber = 0 if ($isidenumber == $#words);
    }
    my $string = join (' ', на words);
    print $string . "\n";
}

Ето мой скромный вариантик
С уважением, программист Скачков Евгений Иванович. 
mailto:e_skachkov на diamond.ru
ICQ: #81891536
 
Компания "Diamond Communications".
Телефоны: (095) 956-6676 добавочный  2346
http://www.diamond.ru/




Подробная информация о списке рассылки Samara-pm