Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
site google



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.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2002
Flim flam flamma Jamma
 

Join Date: May 2001
Localização: Chicago IL, E.U.A.
Posts: 1.006
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
  #2 (permalink)  
Old 01-09-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Usuário
 

Join Date: Nov 2001
Localização: Wide Awake Wylie, Texas
Lugares: 535
É isso o que você está querendo fazer?


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++;
}

print HTML "/table
/html";

Observe que tudo o que fiz foi adicionar a variável $ movieCount »para a declaração acima (@ filmes» e acrescentou uma linha pós-correção para o incremento $ movieCount variável após o «mapa» para a linha de modo que depois de cada ciclo e exibir, $ movieCount irá incremento.

Se não, por favor me avise.
  #3 (permalink)  
Old 01-09-2002
Flim flam flamma Jamma
 

Join Date: May 2001
Localização: Chicago IL, E.U.A.
Posts: 1.006
Acho que vai funcionar.

no fim da página web deve haver um número próximo ao filme assim que eu não ter de contar manualmente manyy como eu tenho.
  #4 (permalink)  
Old 01-09-2002
auswipe's Avatar
auswipe auswipe is offline Forum Advisor  
Usuário
 

Join Date: Nov 2001
Localização: Wide Awake Wylie, Texas
Lugares: 535
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";

  #5 (permalink)  
Old 07-18-2008
Usuário
 

Join Date: Jun 2007
Localização: Beijing China
Posts: 1.133
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>

  #6 (permalink)  
Old 07-18-2008
Usuário
 

Join Date: Jan 2008
Lugares: 729
se você é real? Outra antiga discussão dug up.

01-08-2002
Links Patrocinados
Closed Thread

Marcadores

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Desligado


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



Todos os horários são GMT -4. A hora é agora 02:49.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Brasil Content Copyright © 1993-2010. Todos os direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0