• Publicidad

Renovar array en programa

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Renovar array en programa

Notapor BigBear » 2012-03-28 13:33 @606

Tengo un problema con este código porque no sé cómo renovar el array @urls, ya que la segunda vez que uso el programa aparecen los enlaces viejos.

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!usr/bin/perl
  2. #Lix.In Decoder 0.2
  3. #Version Tk
  4. #Coded By Doddy H
  5.  
  6. use LWP::UserAgent;
  7. use URI::Split qw(uri_split);
  8. use Tk;
  9. use Tk::Dialog;
  10.  
  11. if ( $^O eq 'MSWin32' ) {
  12.     use Win32::Console;
  13.     Win32::Console::Free();
  14. }
  15.  
  16. my $nave = LWP::UserAgent->new;
  17. $nave->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.12) Gecko/20080201Firefox/2.0.0.12");
  18. $nave->timeout(5);
  19.  
  20. my $color_fondo = "black";
  21. my $color_text  = "green";
  22.  
  23. my $ben = MainWindow->new( -background => $color_fondo, -foreground => $color_text );
  24.  
  25. $ben->title("Lix.In Decoder 0.2 (C) Doddy Hackman 2012");
  26. $ben->geometry("492x385+20+20");
  27. $ben->resizable( 0, 0 );
  28.  
  29. $ben->Label( -background => $color_fondo, -foreground => $color_text, -text => "Page : ", -font => "Impact1" )
  30.     ->place( -x => 20, -y => 20 );
  31. my $page
  32.     = $ben->Entry( -background => $color_fondo, -foreground => $color_text, -width => 40 )->place( -x => 73, -y => 24 );
  33.  
  34. $ben->Button(
  35.     -text             => "Decode",
  36.     -width            => 10,
  37.     -command          => \&home,
  38.     -background       => $color_fondo,
  39.     -foreground       => $color_text,
  40.     -activebackground => $color_text
  41. )->place( -x => 325, -y => 23 );
  42. $ben->Button(
  43.     -text             => "Logs",
  44.     -width            => 10,
  45.     -command          => \&logs,
  46.     -background       => $color_fondo,
  47.     -foreground       => $color_text,
  48.     -activebackground => $color_text
  49. )->place( -x => 400, -y => 23 );
  50.  
  51. $ben->Label( -text => "Links Found", -font => "Impact", -background => $color_fondo, -foreground => $color_text )
  52.     ->place( -x => 200, -y => 80 );
  53. my $links = $ben->Listbox( -width => 70, -height => 15, -background => $color_fondo, -foreground => $color_text )
  54.     ->place( -x => 32, -y => 140 );
  55.  
  56. MainLoop;
  57.  
  58. sub home {
  59.  
  60.     my @urls = ("");
  61.  
  62.     $links->delete( "0.0", "end" );
  63.  
  64.     my $url = $page->get;
  65.  
  66.     my $code = toma($url);
  67.  
  68.     while ( $code =~ m{http://lix\.in/(-\w+)}ig ) {
  69.         push( @urls, "http://lix.in/" . $1 );
  70.     }
  71.  
  72.     while ( $code =~ m{http://lix\.in/(\w+)}ig ) {
  73.         push( @urls, "http://lix.in/-" . $1 );
  74.     }
  75.  
  76.     my @urls = repes(@urls);
  77.  
  78.     for my $l (@urls) {
  79.         chomp $l;
  80.         $ben->update;
  81.         decode_link( $l, $url );
  82.     }
  83. }
  84.  
  85. sub decode_link {
  86.  
  87.     my ( $link, $url ) = @_;
  88.  
  89.     my ( $scheme, $auth, $path, $query, $frag ) = uri_split($url);
  90.  
  91.     if ( $link =~ /-(.*)/ ) {
  92.         my $co = "-" . $1;
  93.         chomp $co;
  94.         my $code = tomar( $link, { "tiny" => $co, "submit" => "continue", "submit" => "submit" } );
  95.         if ( $code =~ /<iframe  name="ifram" src="(.*)" marginwidth="0"/ ) {
  96.             my $link = $1;
  97.             chomp $link;
  98.             unless ( $link =~ /lix\.in/ ) {
  99.                 savefile( $auth . ".txt", $link );
  100.                 $links->insert( "end", $link );
  101.             }
  102.         }
  103.     }
  104. }
  105.  
  106. sub logs {
  107.  
  108.     my ( $scheme, $auth, $path, $query, $frag ) = uri_split( $page->get );
  109.     my $f = $auth . ".txt";
  110.  
  111.     if ( -f $f ) {
  112.         system($f);
  113.     }
  114.     else {
  115.         $ben->Dialog(
  116.             -title            => "Error",
  117.             -buttons          => ["OK"],
  118.             -text             => "Logs not found",
  119.             -background       => $color_fondo,
  120.             -foreground       => $color_text,
  121.             -activebackground => $color_text
  122.         )->Show();
  123.     }
  124. }
  125.  
  126. sub repes {
  127.     foreach $test (@_) {
  128.         push @limpio, $test unless $repe{$test}++;
  129.     }
  130.     return @limpio;
  131. }
  132.  
  133. sub savefile {
  134.     open( SAVE, ">>" . $_[0] );
  135.     print SAVE $_[1] . "\n";
  136.     close SAVE;
  137. }
  138.  
  139. sub toma {
  140.     return $nave->get( $_[0] )->content;
  141. }
  142.  
  143. sub tomar {
  144.     my ( $web, $var ) = @_;
  145.     return $nave->post( $web, [ %{$var} ] )->content;
  146. }
  147.  
  148. # The End ?
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4

¿ Alguien me puede ayudar ?
Última edición por explorer el 2012-03-28 15:09 @673, editado 1 vez en total
Razón: Formateado de código con Perltidy y poner marcas Perl
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818

Publicidad

Re: Renovar array en programa

Notapor explorer » 2012-03-28 15:17 @679

No sé a qué te refieres exactamente, pero, por defecto, cuando arranca un programa, ninguna variable "recuerda" el estado de la anterior ejecución (se puede hacer que sí la recuerden, a eso se le llama "persistencia", pero no es el caso en tu programa).

Lo que sí veo es que hay un '>>' en la función de salvar... Si entre ejecuciones no pones a cero el archivo, pues irá creciendo, desde luego.

Otra cosa que quieras hacer es que solo quieres los enlaces que no estén ya grabados en la lista. Para eso, no te queda más remedio que leer esa lista. (O usar un método de "persistencia" :) )
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Renovar array en programa

Notapor BigBear » 2012-03-28 15:43 @697

Bueno, explorer, esta vez me he salvado yo mismo. El problema estaba en la función repes().

Igual: gracias.
BigBear
Perlero frecuente
Perlero frecuente
 
Mensajes: 981
Registrado: 2009-03-01 18:39 @818


Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 45 invitados

cron