fonction sysread [Perl] - Perl - Programmation
Marsh Posté le 22-11-2004 à 12:52:12
python: 
| Code : 
 | 
 
 
Perl: 
 
| Code : 
 | 
Marsh Posté le 22-11-2004 à 13:37:30
moi je le ferais comme ca 
 
| Code : 
 | 
 
 
le code a pas été testé mais ca doit pas être loin de ca 
javais pas le temps ce matin (7hrs36 ici) 
je dois partir, ce soir je regarderai du coté de sysread, ca semble plutot bien comme truc effectivement
Marsh Posté le 22-11-2004 à 13:47:22
sinon selon moi, ton sysread devrait être 
 
| Code : 
 | 
 
 
et non 
 
| Code : 
 | 
 
 
et tes syswrite remplacés par ca 
 
| Code : 
 | 
Marsh Posté le 22-11-2004 à 14:06:27
| Burgergold a écrit : sinon selon moi, ton sysread devrait être  
   | 
 
 
Merci pour tes reponses. 
J'ai rentré ton code mais il ne marche pas... 
 
J'avoue que si mon code peut marcher ça m'arrangerai. 
Je pense que ma synthaxe n'etait pas bonne et que le tienne pour le sysread est ok. 
Cependant, lorsque j'ajoute un print $paq, il ne m'affiche rien. 
Il faut encore chercher....   
 
Marsh Posté le 22-11-2004 à 18:50:55
syswrite et sysread renvoie le nombre d'octets lus ou ecrit 
 
perldoc: 
 
 
############# 
## sysread ## 
############# 
    sysread FILEHANDLE,SCALAR,LENGTH,OFFSET 
    sysread FILEHANDLE,SCALAR,LENGTH 
            Attempts to read LENGTH *characters* of data into variable 
            SCALAR from the specified FILEHANDLE, using the system call 
            read(2). It bypasses buffered IO, so mixing this with other 
            kinds of reads, "print", "write", "seek", "tell", or "eof" can 
            cause confusion because stdio usually buffers data. Returns the 
            number of characters actually read, 0 at end of file, or undef 
            if there was an error. SCALAR will be grown or shrunk so that 
            the last byte actually read is the last byte of the scalar after 
            the read. 
 
            Note the *characters*: depending on the status of the 
            filehandle, either (8-bit) bytes or characters are read. By 
            default all filehandles operate on bytes, but for example if the 
            filehandle has been opened with the ":utf8" I/O layer (see 
            "open", and the "open" pragma, open), the I/O will operate on 
            characters, not bytes. 
 
            An OFFSET may be specified to place the read data at some place 
            in the string other than the beginning. A negative OFFSET 
            specifies placement at that many characters counting backwards 
            from the end of the string. A positive OFFSET greater than the 
            length of SCALAR results in the string being padded to the 
            required size with "\0" bytes before the result of the read is 
            appended. 
 
            There is no syseof() function, which is ok, since eof() doesn't 
            work very well on device files (like ttys) anyway. Use sysread() 
            and check for a return value for 0 to decide whether you're 
            done. 
 
 
 
 
############## 
## syswrite ## 
############## 
    syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET 
    syswrite FILEHANDLE,SCALAR,LENGTH 
    syswrite FILEHANDLE,SCALAR 
            Attempts to write LENGTH characters of data from variable SCALAR 
            to the specified FILEHANDLE, using the system call write(2). If 
            LENGTH is not specified, writes whole SCALAR. It bypasses 
            buffered IO, so mixing this with reads (other than sysread()), 
            "print", "write", "seek", "tell", or "eof" may cause confusion 
            because stdio usually buffers data. Returns the number of 
            characters actually written, or "undef" if there was an error. 
            If the LENGTH is greater than the available data in the SCALAR 
            after the OFFSET, only as much data as is available will be 
            written. 
 
            An OFFSET may be specified to write the data from some part of 
            the string other than the beginning. A negative OFFSET specifies 
            writing that many characters counting backwards from the end of 
            the string. In the case the SCALAR is empty you can use OFFSET 
            but only zero offset. 
 
            Note the *characters*: depending on the status of the 
            filehandle, either (8-bit) bytes or characters are written. By 
            default all filehandles operate on bytes, but for example if the 
            filehandle has been opened with the ":utf8" I/O layer (see 
            "open", and the open pragma, open), the I/O will operate on 
            characters, not bytes.
Marsh Posté le 25-11-2004 à 14:05:54
  
  
Un petit Up car marche toujours pas   
  
Merci pospos pour ces détails, mais j'ai du mal à cerner SCALAR. 
 
Dans ma fonction sub collect, lorsque je fais un print fsource, il ne m'affche rien. ça défile mais avec rien comme caractères. 
Par contre lorsque je fais un print de fsource hors de la fonction ça marche....
Marsh Posté le 25-11-2004 à 14:21:35
en perl tu as 3 type de conteneur par défaut 
 
le scalar: une variable seule 
l'array: un tableau de scalar 
le hash: un array associatif (key->value) où key est un scalar et value aussi 
 
Marsh Posté le 25-11-2004 à 14:42:26
Bon j'avance mais à petit pas... 
Merci pour votre participation. pas facile quand on débute   
  
 
 
| Code : 
 | 
 
 
Lorsque j'active le print dans la boucle de fsource, rien ne s'affiche. 
Lorsque j'active le print de $paq par contre il m'affcihe les 50 premiers caractères. 
Par contre: 
Lorsque j'active le print dans le programme, il m'affiche tout fsource 
 
En fonction de la position de $i, j'ai soit 0 ou la taille complète en nombre de caractère de mon fichier. 
 
 
Resultat: je n'ai que les 50 premiers caractères de copié. La fonction n'est pas relancé... 
Marsh Posté le 25-11-2004 à 14:47:10
ta fonction collect sert pas à grand chose, pk tu la place pas directement dans ton while? 
 
et ajoute au début de ton script "use strict;" 
ainsi que des "my" devant chaque déclaration de nouvelle variable
Marsh Posté le 22-11-2004 à 12:29:38
Bonjour,
je débute à la fois en python et en perl.
J'ai fait un script en python qui marche bien, et je veux faire le même en Perl.
Cependant je suis en train de butter sur la fonction Sysread de perl.
Ce script a pour but de recolter 50 caractères d'une chaine de caractères. Je vous expose ici que la fonction du programme:
Voila en python se que ma fonction donne:
fsource est donc la variable qui correspond à mon fichier ouvert.
fnuc est la variable qui écrit mes 50 caractères dans un nouveau fichier.
En perl j'en suis là:
En fait je ne sais pas quoi mettre après fsource? Certainement pas $paq
Merci pour votre aide!