23/05/2004 - Script em Perl para mostrar notícias do Notícias Linux #!/usr/bin/perl =pod Script Perl para mostrar noticias do RSS do site Noticias Linux (http://www.noticiaslinux.com.br) Desenvolvido por: Eduardo Bacchi Kienetz eduardo [arroba] noticiaslinux.com.br Data: 24/02/2004 Alterações: 23/05/2004 - Passa a ler o RSS de $tempo em $tempo para nao sobrecarregar os servidores. Criar um arquivo noticias_linux.xml em branco e: chmod 666 noticias_linux.xml Este script pode ser distribuido, modificado e usado livremente. =cut use strict; use IO::Socket; use URI; use File::stat; my $tempo = 1800; my $arquivo = stat("noticias_linux.xml"); my $modif = $arquivo->mtime; my $tmp; my $rss; my $i; print "Content-type: text/html\n\n"; if(((time() - $tempo) > $modif) || $arquivo->size < 15 ){ my $onde = "http://www.noticiaslinux.com.br"; my $url = new URI( $onde ); my $host = $url->host; my $port = $url->port || 80; my $path = $url->path || "/rss.php"; my $socket = new IO::Socket::INET (PeerAddr => $host, PeerPort => $port, Proto => 'tcp') or die "Impossivel conectar ao servidor.\n"; $socket->autoflush (1); print $socket "GET $path HTTP/1.1\n", "Host: $host\n\n"; while ($tmp = <$socket>){ $rss .= $tmp; } open(FILE,">noticias_linux.xml") or die "Incapaz de abrir arquivo!"; print FILE "$rss"; close FILE; $socket->close; } else { open(FILE,"noticias_linux.xml") or die "Incapaz de abrir arquivo!"; while($tmp = ) { $rss .= $tmp; } close(FILE); } print "Notícias Linux\n"; while ($rss =~ /.(.+)<\/title>\n.+(.+)<\/link>/ig){ if($i == 1) { print "".$1."\n"; } $i=1; } print "Mais notícias ...\n";