[EMAIL PROTECTED] wrote:
> Thanks a bunch. The code works great. I was wondering... Is there a way that
> after writing the first 50 characters of a certain file, that the script
> could skip the next 50 characters, and then continue and write the next 50?
>
> Thanks in advance.
> -------------------------------------------The code so far---
> open D_IN, "<TheFile.txt" or die "Not found";
> open D_OUT, ">TheFile50.txt" or die "Cannot write";
>
> $count = read D_IN, $fifty, 50;
> print D_OUT $fifty;
>
> print $fifty;
=cut
Hi Wireless,
Save this script and let it run.
First let the machine produce some data:
=cut
open D_OUT1, ">TheFile.txt" or die "Cannot write";
for (1..20) {
printf D_OUT1 "Line %02.0f: 1234567890123456789012345678901234567890\n", $_;
}
print " finished (1)";
# - - - - - - -
# Skip the 2nd 50 characters:
open D_IN, "<TheFile.txt" or die "Not found";
open D_OUT, ">TheFile50.txt" or die "Cannot write";
read D_IN, $fifty, 50;
print D_OUT $fifty;
read D_IN, $fifty, 50;
read D_IN, $fifty, 50;
print D_OUT $fifty;
print "\n F i n i s h e d ( 2 ) . ";
# - - - - - - - -
# But maybe this is what you wanted:
# Skip every 2nd 50 characters:
open D_IN, "<TheFile.txt" or die "Not found";
open D_OUT, ">TheFile50_loop.txt" or die "Cannot write";
while (read D_IN, $fifty, 50) {
print D_OUT $fifty;
read D_IN, $fifty, 50; }
print "\n F i n i s h e d ( 3 ) . ";
=If you want to know how to skip
100 characters: feel free to ask. :-)
If you want to find out how to craft
such tasks by your own: RTFM (read the
fine manual) about loops, play around,
test everything or ask your children ;-) .
And use in MacPerl the Shuck Help Function:
Put the cursor on
while
sprintf (instead of printf) and the like
and press command H
and you'll gain a wealth of knowledge.
Greetings, Detlef