develooper Front page | perl.beginners | Postings from May 2023

RE: storage types for big file

Thread Previous | Thread Next
From:
Tom Reed
Date:
May 31, 2023 01:30
Subject:
RE: storage types for big file
Message ID:
acbfe61eb3d191a3c49d1b06e9b1ec78.squirrel@dkinbox.com

Hello

I am not sure,

                <change $line, making sure the length (in bytes) doesn't
change>


what does this mean? not changing the line length?
but in most case I need to change the length of a line.

Thanks again.
Tom



> That sounds positive.  You should be able to avoid most of the overhead of
> writing the file.   The general idea is that you are "updating in place"
> rather than writing out the whole file.
>
> Something like below is what I was thinking, but it isn't tested!  Make
> sure you have a copy of your input file.  Oh, and I haven't thought about
> "wide" characters which may influence how some of this works.
>
> Cheers,
>
> Claude.
>
>
> open(my $fh, "+<", $theFileName) or die "open: $!";
>
> my $startOfLine = tell($fh) or die "tell: $!;
> while (defined(my $line = <$fh>))
> {
> 	if ($line has content that needs to change)
> 	{
> 		<change $line, making sure the length (in bytes) doesn't change>
> 		seek($fh, $startOfLine, 0) or die "seek: $!";
> 		print $fh $line;
> 	}
>
> 	$startOfLine = tell($fh) or die "tell: $!;
> }
>
> close($fh);
>
>
> -----Original Message-----
> From: Tom Reed <tom@dkinbox.com>
> Sent: Wednesday, May 31, 2023 9:33 AM
> To: Claude Brown <claude.brown@gigacomm.net.au>
> Cc: beginners@perl.org
> Subject: RE: storage types for big file
>
>
>
>> Do you have the option to "seek" to the correct place in the file to
>> make
>> your changes?  For example, perhaps:
>>
>> - Your changes are few compared to writing out the whole file
>> - Your changes do not change the size of the file (or you can pad
>> line-end
>> with spaces)
>>
>
> 1. each time just changes few lines, not the full file.
> 2. it has file size changed, but yes I can pad line-end with space.
>
> So what's the further?
>
> Thanks
>
>
> --
> Sent from https://dkinbox.com/
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


-- 
Sent from https://dkinbox.com/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About