SoloCodigo

Programación Web y Scripting => Perl => Mensaje iniciado por: tenesor en Martes 12 de Febrero de 2002, 18:41

Título: Re: Lectura de ficheros binarios
Publicado por: tenesor en Martes 12 de Febrero de 2002, 18:41
Hola a todos. Esta vez yo tengo el problemilla.

Necesito leer un fichero en binario y para ello debo especificar la longitud. la expresion es asi:

   sysread FILE, $buffer, $longitud

Teniendo en cuenta que lo que quiero es leer todo el fichero, como puedo hacer para calcular la longitud de dicho fichero?

Saludos,
   Tenesor
Título: Lectura de ficheros binarios
Publicado por: francisco23 en Miércoles 25 de Septiembre de 2002, 22:21
prueba con esto para averiguar el tamaño del archivo

stat FILEHANDLE

stat EXPR

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. Typically used as follows:
    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
       $atime,$mtime,$ctime,$blksize,$blocks)
           = 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 seconds since the epoch
 11 blksize  preferred block size for file system I/O
 12 blocks   actual number of blocks allocated

fue sacado de la ayuda de activeperl
mira "perlfunc - Perl builtin functions"
Espero que te ayude.