One of the requirements I have is to create a log that indicates which record the TR actually modified. Any ideas on how to do this whilst retaining the performance?
I would make the buffer size a multiple of the fixed record size. The non-power-of-two-ness may have a slight impact on the performance, but it will probably be negligable.
I would then perform the translation on record-sized chunks of the buffer, by using substr as an lvalue; something like:
my $recno = 0;
while( sysread $FH, $buffer, $RECSIZE * $MULTIPLE ) {
my $readPos = sysseek $FH, 0, 1; ## simulate "systell()".
for( 0 .. $MULTIPLE - 1 ) {
if( my $changed
= substr( $buffer, $_ * $RECSIZE, $RECSIZE )
=~ tr[...][...]
) {
print LOG "Changed $changed chars in record: ", $recno + $
+_;
# Calculate positions of modified record.
+
my $writePos = ( $recno + $_ )* $RECSIZE ; ## Check this c
+alc! Untested!
sysseek $FH, $writePos, 0;
syswrite $fh, substr( $buffer, $_ * $RECSIZE, $RECSIZE );
sysseek $FH, $readPos, 0; ## Restore read position if we m
+oved it.
}
}
$recno += $MULTIPLE;
}
There are few things to note here:
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.