![]() |
|
|
google unix.com
|
|||||||
| Fóruns | Registar | Fórum Regimento | Ligações | Álbuns | FAQ | Lista deputados | Calendário | Pesquisa | Today's Posts | Mark Forums Read |
| Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui. |
Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
|
||||
| Fio | Thread Starter | Fórum | Respostas | Última postagem |
| Procurar, substituir string em ficheiro1 com seqüência de (tabela) ficheiro2? | gstuart | Programação Shell Script e | 9 | 06-08-2009 07:11 |
| libapache2-mod-scramble-ip 0.2 (Default sucursal) | iBot | Software Release - RSS Notícias | 0 | 07-10-2008 07:50 |
| Corrida dos Ovos 1,1 (Padrão sucursal) | iBot | Software Release - RSS Notícias | 0 | 05-04-2008 06:30 |
| anexando string para arquivo texto com base em pesquisa string | malaymaru | Programação Shell Script e | 1 | 06-09-2006 09:53 |
| sed problema - substituição cadeia deve ser o mesmo comprimento que matching string. | amangeles | Programação Shell Script e | 4 | 01-11-2006 06:11 |
![]() |
|
|
Linkback | Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Corrida uma corda.
Oi tudo,
Estou tentando escrever um perl script que terá entrada de usuário como um string e codificar a string e imprimir o resultado. Nota: Não é possível usar função shuffle .... utilizando para loop. Código:
so here is example. Enter a String: abcdef Print the Result: debacf Enter a String: abcdef print the Result: cdabef Código:
print "Enter a string: ";
$sString = <STDIN>;
chomp($sString);
print "String = $sString\n";
$iLength = length($sString);
@array = split(//, $sString);
print "array = @array\n";
print "length = $iLength\n";
for ( $i = 1; $i <= $iLength; $i++ ){
$item = int(rand($#array));
print "@array[$item]\n";
}
obrigado, |
|
||||
|
A maneira mais simples é a de ciclo através da matriz swapping cada item com outro item em uma posição aleatória. Observe que o array é indexado de 0 e não 1.
Código:
for ( $i = 0; $i < $iLength; $i++ ){
$random = int(rand($#array));
$temp=$array[$random];
$array[$random]=$array[$i];
$array[$i]=$temp;
}
for ( $i = 0; $i < $iLength; $i++ ){
print "$array[$i]";
}
print "\n";
|
|
||||
|
|
![]() |
| Marcadores |
| Thread Tools | Pesquisar este Thread |
| Display Modes | Esta taxa Thread |
|
|