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?
The first loop is not very good indeed, since it's an infinite loop. Just few tips to get you started:
my $cnt = 0; while (1 == 1) {
This is an infinite loop. It keeps running while 1 equals 1, i.e. pretty much always. This is why your program hangs.
open IN, "<", "/dev/nst0" || die "cant open ...\n";
die is never run, because the string "/dev/nst0" is never false.
Run this:
perl -le 'open F, "<", "/no/such/file" || die; print "OK"'
It prints OK. Read the first paragraph of perldoc perlop SYNOPSIS about operators precedence.
while (@out = <IN>) {
It reads the entire file (tape) all at once and store its lines in @out array. Read "I/O Operators" in perldoc perlop.
$cnt++; open OUT, ">", "$cnt.bin" || die "cant open out\n";
Again, die is never reached here.
print OUT "@out\n";
This is equivalent to:
print OUT join($", @out), "\n";
which is most likely equivalent to:
print OUT join(" ", @out), "\n";
which is probably not what you want.
close OUT; } }
This is never reached because the above curly is enclosing an infinite loop without an explicit "last" command.
close IN;
What do you mean by 'several files with "end of file markers"'? Is it a stream of your original files concatenated with ^D, "\cd" inserted in between them? Are those only text files with no ^D in them? Does this command:
less -f /dev/nst0
show those text files? Does this command:
less -fE /dev/nst0
show the first one of them? Are you sure the files on tape are not stored in a tarfile format? You have to describe how does your data look like.
-- ZSDC Perl and Systems Security Consulting
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>