#!/usr/bin/env perl use 5.010; use strict; use warnings; use autodie; { say "\n*** Test +< (r+)"; say 'Open file'; open my $fh, '+<', 'test1.txt'; say 'Position in file: ', tell $fh; say 'Read to end of file'; print while <$fh>; say 'Position in file: ', tell $fh; } { say "\n*** Test +> (w+)"; say 'Open file'; open my $fh, '+>', 'for_del.txt'; say 'Position in file: ', tell $fh; say 'Read to end of file'; print while <$fh>; say 'Position in file: ', tell $fh; } { say "\n*** Test +>> (a+)"; say 'Open file'; open my $fh, '+>>', 'testq.txt'; say 'Position in file: ', tell $fh; say 'Read to end of file'; print while <$fh>; say 'Position in file: ', tell $fh; say 'Write a record'; say $fh 'r'; say 'Position in file: ', tell $fh; say 'Rewind to start of file'; seek $fh, 0, 0; say 'Position in file: ', tell $fh; say 'Read to end of file'; print while <$fh>; say 'Position in file: ', tell $fh; } #### ken@titan ~/tmp/pm_11152251_file_rwa $ ls -l *.txt -rw-r--r-- 1 ken None 6 May 19 01:41 for_del.txt -rw-r--r-- 1 ken None 6 May 19 01:16 test1.txt -rw-r--r-- 1 ken None 6 May 19 01:40 testq.txt ken@titan ~/tmp/pm_11152251_file_rwa $ cat test1.txt 1 2 3 ken@titan ~/tmp/pm_11152251_file_rwa $ cat for_del.txt z x c ken@titan ~/tmp/pm_11152251_file_rwa $ cat testq.txt q w e ken@titan ~/tmp/pm_11152251_file_rwa $ #### ken@titan ~/tmp/pm_11152251_file_rwa $ ./read_write_append.pl *** Test +< (r+) Open file Position in file: 0 Read to end of file 1 2 3 Position in file: 6 *** Test +> (w+) Open file Position in file: 0 Read to end of file Position in file: 0 *** Test +>> (a+) Open file Position in file: 6 Read to end of file Position in file: 6 Write a record Position in file: 8 Rewind to start of file Position in file: 0 Read to end of file q w e r Position in file: 8 ken@titan ~/tmp/pm_11152251_file_rwa $ #### ken@titan ~/tmp/pm_11152251_file_rwa $ ls -l *.txt -rw-r--r-- 1 ken None 0 May 19 01:42 for_del.txt -rw-r--r-- 1 ken None 6 May 19 01:16 test1.txt -rw-r--r-- 1 ken None 8 May 19 01:42 testq.txt ken@titan ~/tmp/pm_11152251_file_rwa $ cat test1.txt 1 2 3 ken@titan ~/tmp/pm_11152251_file_rwa $ cat for_del.txt ken@titan ~/tmp/pm_11152251_file_rwa $ cat testq.txt q w e r ken@titan ~/tmp/pm_11152251_file_rwa $