Article View: es.comp.os.linux.programacion
Article #10502Re: [Perl-Novato] Encontrar un fichero index.*
From: aktin0s
Date: Mon, 25 Feb 2002 16:59
Date: Mon, 25 Feb 2002 16:59
61 lines
2749 bytes
2749 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 25.02.2002, David wrote in es.comp.os.linux.programacion
> Estoy desarrollando un script en Perl que, entre otras cosas, debe
> meterse en un directorio y ver si encuentra un fichero que se llame
> index.* (es decir, index.html o index.php, etc).
>
> Se me ocurren dos formas de hacerlo, pero no tengo muy claro c�mo
> pulirlo.
>
> Una:
> $comando = system("ls /mi/directorio/index.*");
> y tratar de capturar lo que me sacar�a por la consola esta llamada. Se
> que en $comando lo que me aparecer�a ser�a un 0 si se ejecuta la
> llamada, pero no se si se podr�a capturar la salida.
>
> Dos:
> Tratar de hacer un open del fichero y ver si consigue abrir el
> fichero:
> open( FICHERO_INDEX , $fichero_index )) || die( "Cachis la mar...");
> pero poniendo en $fichero_index una expresi�n regular del tipo
> /index\.*/, pero lo dicho, no tengo muy claro c�mo hacerlo.
>
> �Alguna sugerencia o enlace interesante?
> Por ahora he buscado en el "PERL Quick Reference" de M�che�l � Foghl�
> y en el "Teach Yourself Perl 5 in 21 days" de David Till, pero no me
> ha sido de gran ayuda.
Puedes usar File::Find, un ejemplo
#!/usr/bin/perl -w
use strict;
use File::Find;
my ( $dir ) = @ARGV;
find( \&index, $dir );
sub index
{
$File::Find::prune = 1
if ( -d && $File::Find::name ne $File::Find::topdir);
print "$File::Find::name\n"
if ( -f && /index\./ );
}
Espero que te sirva, saludos.
- --
David Sotelo Fern�ndez (aktin0s)
GnuPG key id 0x3CF68D01, pgp.mit.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
iD8DBQE8emvWJ/HgPjz2jQERAmxlAJ0fDBTouSHQkiqmPi5QsY2s91QpDwCggbZN
SKJg78lCszr/Q2YejbI0w/Q=
=evlK
-----END PGP SIGNATURE-----
Technical Details
Message-ID:
<6iqd5a.cc4.ln@gw.kn0wledge.lan>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!cm12441.telecable.ES!not-for-mailReferences:
<1759581e.0202250600.7020a360@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,91055ca77b044ab2 X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2002-02-25 09:29:37 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!cm12441.telecable.ES!not-for-mail From: aktin0s <aktin0s@gmx.net> Newsgroups: es.comp.os.linux.programacion Subject: Re: [Perl-Novato] Encontrar un fichero index.* Date: Mon, 25 Feb 2002 17:59:50 +0100 Lines: 61 Message-ID: <6iqd5a.cc4.ln@gw.kn0wledge.lan> References: <1759581e.0202250600.7020a360@posting.google.com> NNTP-Posting-Host: cm12441.telecable.es (213.141.56.252) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fu-berlin.de 1014658174 6786440 213.141.56.252 (16 [99261]) X-Orig-Path: gw.kn0wledge.lan!nobody User-Agent: slrn/0.9.7.3 (Linux)