[Perl] AYUDA !!!!

Gunnar Wolf gwolf@campus.iztacala.unam.mx
Thu, 25 Apr 2002 17:36:42 -0600 (CST)


> Lista,
>
> Necesito su ayuda. Necesito hacer un script en perl pero
> para eso necesito identificar subdirectorios y archivos. Por
> ejemplo
>
> /home/uno/
>             /dos/
>             /tres/
>             /cuatro/
>
> y ya que edintifique los directorios necesito identificar y
> clasificar los archivos que estan en cada directorio y bueno
> mi preguta es como le puedo hacer para ir recorriendo cada
> directorio y como le puedo hacer para diferenciar entre un
> directorio y un archivo. Por otro lado como puedo hacer para
> checar el tama=F1o de los archivos por medio del script.

Con la funci=F3n stat. De perldoc -f stat:

       stat    Returns a 13-element list giving the status info
               for a file, either the file opened via FILEHANDLE,
               or named by EXPR.  If EXPR is omitted, it stats
               $_.  Returns a null list if the stat fails.  Typi-
               cally used as follows:

                   ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
                      $atime,$mtime,$ctime,$blksize,$blocks)
                          =3D stat($filename);

               Not all fields are supported on all filesystem
               types.  Here are the meaning of the fields:

                 0 dev      device number of filesystem
                 1 ino      inode number
                 2 mode     file mode  (type and permissions)
                 3 nlink    number of (hard) links to the file
                 4 uid      numeric user ID of file's owner
                 5 gid      numeric group ID of file's owner
                 6 rdev     the device identifier (special files only)
                 7 size     total size of file, in bytes
                 8 atime    last access time in seconds since the epoch
                 9 mtime    last modify time in seconds since the epoch
                10 ctime    inode change time (NOT creation time!) in secon=
ds since the epoch
                11 blksize  preferred block size for file system I/O
                12 blocks   actual number of blocks allocated

(...)

> Por otro lado como puedo hacerle y necesito encontrar un
> string dentro de un archivo tipo txt usando perl??..

Si lo quieres hacer estrictamente *dentro* de Perl, abres el archivo y
buscas l=EDnea por l=EDnea, ya sea contra una expresi=F3n regular (m=E1s po=
deroso)
o con un index (m=E1s r=E1pido - Aunque ac=E1 lo que determinar=E1 la veloc=
idad es
m=E1s bien el disco duro, pero...)

Si te atreves a salirte un poco de Perl, un $aparece=3D`grep cadena archivo=
`
te puede servir.

--=20
Gunnar Wolf - gwolf@campus.iztacala.unam.mx - (+52-55)5623-1118
PGP key 1024D/8BB527AF 2001-10-23
Fingerprint: 0C79 D2D1 2C4E 9CE4 5973  F800 D80E F35A 8BB5 27AF