De acordo com as Leis 12.965/2014 e 13.709/2018, que regulam o uso da Internet e o tratamento de dados pessoais no Brasil, ao me inscrever na newsletter do portal DICAS-L, autorizo o envio de notificações por e-mail ou outros meios e declaro estar ciente e concordar com seus Termos de Uso e Política de Privacidade.
Colaboração: Gustavo Chaves
Data de Publicação: 04 de Agosto de 2000
Aproveitando a deixa da mensagem sobre o justificador de texto com sed, enviada pelo Aurelio, o Gustavo me enviou um script similar que realiza a tarefa com perl:
#!/usr/bin/perl -w # justify - justify text lines. # $Id: justify,v 1.2 2000/07/21 20:01:33 gustavo Exp $ $columns = 65; while (<>) { s/\s+$/\n/; # trim trailing spaces next unless $columns > length; # skip big lines @words = split /(?<=\S)\s+/; # split it preserving leading spaces $inter = @words - 1; # number of interword spaces next unless $inter > 0; # skip single worded and blank lines $length = 0; $length += length foreach @words; # sum up the size of the words $spaces = $columns - $length; # how many spaces for the line $blanks = int($spaces / $inter); # how many spaces for each interword $extra = $spaces % $inter; # extra spaces due to rounding next if ($blanks + !!$extra) > 5; # skip if we have to add too much space # Go on, rebuild the line. $_ = ''; for ($i=0; $i<$inter; ++$i) { $_ .= $words[$i] . ' ' x ($blanks + ($i<$extra)); } $_ .= $words[$i] . "\n"; } continue { print; }
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Comentários