[EMAIL PROTECTED] wrote: > Hi All, > > I am trying to read some data from af unix tape device. The have several files with > "end of file markers". Can I read from tape devices at all? > > I tried "open" on the device and this one reads all files on the tape into the first > file and then hangs. Is it my code (I know the first loop is not very good:-) or > does perl not recognise or honer the EOF marks? > > Thanks, > Jakob > > my $cnt = 0; > while (1 == 1) { > open IN, "<", "/dev/nst0" || die "cant open ...\n"; > while (@out = <IN>) {
Why are you using an array?. That puts the read operator in list context, so that it reads all lines of the file into the @out array on the first round through the loop. > > $cnt++; Please use vowels. They are neither poisonous nor explosive. > > open OUT, ">", "$cnt.bin" || die "cant open out\n"; > print OUT "@out\n"; > close OUT; > } > } > close IN; The code above probably does exactly what you are telling it to do. On the first round, it sucks all lines offered in text mode by the strream from the tape drive. Then it reaches EOF. At this point there is nothing left to read in the file, so the whole array, containing the first text file on the tape, is output to the file. It is good that you have an ambitious project in mind for Perl programming. I suspect that you will need to get much more familiar with the basics of Perl programming, as well as general file-storage principles, before you can do justice to the job. Have you had success in reading and processing individual files in a variety of situations? This would be a good place to start. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>