in reply to Re:^4 Binary file handling
in thread Binary file handling
It is Perl reporting an OS message. Consided open F, $foo or die $! say you get permission denied, that is an OS message delivered via perl.
You don't have to use real file descriptors. You could simply open a DBM database or a tied hash, pretend that the keys are the file descriptors and just append to the values. It actually simplifies the code, but it will be a big speed hit.
Here is one of the examples from Re: Binary file handling converted to use a hash tied to a file.
sub rotate_minus90 { my ( $infile, $outfile, $tmp ) = @_; $tmp ||= 'c:/tmp/temp'; open IN, $infile or die "Can't read $infile $!\n"; # find number of columns and open a temp file for each chomp( local $_ = <IN> ); my @data = split ' '; my $num_cols = $#data; dbmopen(my %fhs, $tmp, 0666) or die "dbmopen can't grok $tmp $!\n" +; $fhs{$_} = "$data[$_]\t" for 0..$num_cols; while( <IN> ) { chomp; @data = split ' '; $fhs{$_} .= "$data[$_]\t" for 0..$num_cols; } close IN; open OUT, ">$outfile" or die "Can't write $outfile $!\n"; for ( reverse 0.. $num_cols ) { print OUT $fhs{$_}, "\n"; } dbmclose(%fhs); close OUT; }
cheers
tachyon
|
|---|