|
|
|
|
site google
|
|||||||
| Fóruns | Registar | Blog | Man Pages | Fórum Regimento | Ligações | Álbuns | FAQ | Usuários | 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. |
![]() |
|
|
Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
|||
|
perl + array e incrementar número
Gals manhã e caras, Estou haveing um problema, um amigo me ajudou com este script, mas eu não sei como adicionar número incrementado para cada filme em movie.list. isto é o que tenho até agora. qualquer ajuda seria ótimo. Eu tenha removido o GT e LT símbolos para que você possa ver o que está acontecendo no array. Código:
#! /usr/bin/perl -w
use strict;
my $src_list = 'movie.list';
open SRC, $src_list or die "Couldn't read $src_list: $!\n";
my @movies = sort <SRC>;
my $dst_list = 'dvd-list.html';
open(HTML, "> $dst_list") or die "Can't write to $dst_list: $!\n";
print HTML "
my basic html goes here";
for (@movies) {
# The order here needs to be fixed.
my ($title, $run_time, $mpaa_rating, $genre, $prod_company) = split ':', $_;
print HTML "tr";
# Make sure we get no undef vars.
print HTML "td $_ /td"
for map {$_ || ''} $title, $run_time, $mpaa_rating, $genre, $prod_company;
print HTML "/tr\n";
}
print HTML "/table
/html"; |
| Links Patrocinados |
|
|
|
||||
|
Ooooohhh. Então, tente o seguinte: Código:
#! /usr/bin/perl -w
use strict;
my $src_list = 'movie.list';
open SRC, $src_list or die "Couldn't read $src_list: $!\n";
my @movies = sort ;
my $dst_list = 'dvd-list.html';
open(HTML, "> $dst_list") or die "Can't write to $dst_list: $!\n";
print HTML "
my basic html goes here";
# Add variable to display "Current Record Number"
my $movieCount = 1;
for (@movies) {
# The order here needs to be fixed.
my ($title, $run_time, $mpaa_rating, $genre, $prod_company) = split ':', $_;
print HTML "tr";
# Make sure we get no undef vars.
print HTML "td $_ /td"
for map {$_ || ''} $movieCount $title, $run_time, $mpaa_rating, $genre, $prod_company;
print HTML "/tr\n";
# Increment $movieCount by one with each display
$movieCount++;
}
$movieCount--;
print HTML "(br)(b) There are $movieCount movies in the library.(/b)\n";
print HTML "/table
/html"; |
|
|||
|
entrada: Código:
leo:30 stt:25 tony:31 código: Código:
open SFH,"<staff.txt" or die "Can not open file";
open HFH,">staff.html" or die "Can not open file";
print HFH "<HTML>\n";
while(<SFH>){
print HFH "<member",$.,">\n";
my ($name,$age)= split ":",$_;
$age=~ tr/\n//d;
print HFH "<name> ",$name," </name>\n";
print HFH "<age> ",$age, "</age>\n";
print HFH "</member",$.,">\n";
}
print HFH "</HTML>\n";
close(HFH);
close(SFH);Saída: Código:
<HTML> <member1> <name> leo </name> <age> 30</age> </member1> <member2> <name> stt </name> <age> 25</age> </member2> <member3> <name> tony </name> <age> 31</age> </member3> </HTML> |
|
|||
|
se você é real? Outra antiga discussão dug up.
01-08-2002 |
| Links Patrocinados | ||
|
|
![]() |
| Marcadores |
| Thread Tools | Pesquisar este Thread |
| Display Modes | Esta taxa Thread |
|
|
Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
|
||||
| Fio | Thread Starter | Fórum | Respostas | Última postagem |
| perl-escrever valores em um arquivo para @ array em perl | meghana | Programação Shell Script e | 27 | 06-07-2009 06:05 |
| Array comprimento em Perl | anent | Programação Shell Script e | 5 | 07-17-2008 05:39 |
| como chegar até ao último valor em um array em perl | meghana | Programação Shell Script e | 7 | 02-04-2008 05:12 |
| array multidimensional em perl | prkfriryce | Programação Shell Script e | 9 | 12-01-2007 04:33 |
| hash, array e perl | new2ss | Programação Shell Script e | 3 | 05-23-2007 12:30 |