use strict; use warnings; use Config; print STDERR qq!Perl $^V on $^O arch $Config{archname}\n!; sub demo { my ($s1, $s2) = ('',''); my $sFormat = "s1='%s' s2='%s'\n"; open(my $fh1, '>', \$s1) or die "Can't open fh1"; print $fh1 'Hi Thing One'; printf STDERR $sFormat, $s1, $s2; # => s1='Hi Thing One' s2='' open(my $fhSave, '>&', $fh1) or die "Can't save fh1"; close $fh1; open($fh1, '>', \$s2) or die "Can't redirect fh1"; print $fh1 'Hi Thing Two*Bye Thing Two'; printf STDERR $sFormat, $s1, $s2; # => s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' # PICK ONE OF TWO OPEN OPTIONS BELOW #1# #print STDERR "Option 1\n"; open($fh1, '>&', $fhSave) or die "Can't restore fh1"; #2# #print STDERR "Option 2\n";open($fh1, '>', \ substr($s1, length($s1)) ) or die "Can't restore fh1"; print $fh1 '*Bye Thing One'; printf STDERR $sFormat, $s1, $s2; # OUTPUT FROM OPEN OPTIONS #1# => s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' #2# => s1='Hi Thing One*Bye Thing One' s2='Hi Thing Two*Bye Thing Two' } demo(); exit(0);