Brian Volk wrote:
>
> Is it possible to open a file and print to a specific location in the file?
> For example, I have a 1K file and 0 - 511 is where the small description is
> stored and starting in position 512 is the path to a pdf file.... If I do
> not have the path in position 512 the link will be broken on web site. Pls
> let me know if this is possible and where I can read about it.
>
> I think I found what I was looking for... ( seek / read )
>
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
>
> my $txt_file = "C:/brian/descriptions/product/small/70413.txt";
> open (FILE, $txt_file) or die "can't open $txt_file: $!\n";
>
> my $link;
>
> seek (FILE, 256, 0);
> read (FILE, $link, 150);
>
> print $link;
> ---------------------------------------------------
> now I just hope I can open the file replace the data in that byte
> position... :~)
1) You need to open the file for both read and write.
open FILE, '+<', $txt_file or die ...;
2) You probably need to remove/add trailing padding when
reading/writing the data.
perldoc -f pack
perldoc -f unpack
perldoc -f substr
3) You should verify all system calls including seek() and read().
4) You should probably include the seek macros from the Fcntl module.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>