I am reading a binary file and I am using the tell() function to get the specific position of a location. I am reading the file in binary mode:
open( FH , "+<" , $source ) or die "Can not open file: $source $!\n"; binmode(FH);
I am moving the pointer to the desired position with string condition and using:
$position = tell(FH)
In order to get the pointer position int. Then I use SEEK to move to the position that I have previously marked by doing:
seek( FH , $position , SEEK_SET );
Where I am issuing the commang:
write( FH, $example , $example_size ) or die "Couldn't write at FH : $!\n";
I was browsing over the internet and I found that the opposite of read() is not write(). But later on trying to find a solution to my problem I came across with the Perl man page perlapio − perl’s IO abstraction interface. and also perlclib.
Both of the web pages state that the alternative of fwrite() in C is write():
fwrite(p, size, n, stream) PerlIO_write(perlio, buf, numbytes)
I tried to apply that in my code and I keep getting this error:
Useless use of a constant (FH) in void context at test.pl line 193.
I looked online what is the error and I found that it can not open the file properly. I do have a die condition on open and also I have a few printf() conditions to test if the file is opening and they are coming up. So at this point I assume it is a wrong syntax with the write() function. Are there any alternatives that I could use?
Thanks in advance for your time and effort.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |