#!/usr/bin/perl use strict; use warnings; open (my $junkfile, '>', "junkfile"); my $junk = ''; for my $first_byte (0 .. 255) { for my $second_byte (0 .. 255) { $junk .= pack('CC', $first_byte, $second_byte); $junk .= "\0" x 2; } } print $junkfile $junk; close $junkfile; open(my $orig, '<', "junkfile") or die $!; seek( $orig, 256, 0); print_locations("Locations after seeking ORIG to 256: "); my $correct; read($orig, $correct, 8); print_locations("Locations after reading 8 bytes from ORIG: "); my @bytes = unpack('C*', $correct); print "ORIG read these bytes: @bytes\n"; open(my $dupe, "<&", $orig) or die $!; print_locations("Locations immediately after duping: "); seek( $dupe, 256, 0); print_locations("Locations after seeking DUPE to 256: "); seek($orig, 120, 0); print_locations("Locations after seeking ORIG to 120: "); my $useless; read($orig, $useless, 20); print_locations("Locations after reading 20 bytes from ORIG: "); my $test; read($dupe, $test, 8); print_locations("Locations after reading 8 bytes from DUPE: "); @bytes = unpack('C*', $test); print "DUPE read these bytes: @bytes\n"; sub print_locations { my $label = shift; print "$label\n "; print "ORIG " . tell($orig) . " "; print "DUPE "; print defined $dupe ? tell($dupe) : "not valid"; print "\n"; }