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); #### #option 1 ----------------------------------------······· | Perl v5.14.2 on MSWin32 arch MSWin32-x86-multi-thread | s1='Hi Thing One' s2='' | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' | Option 1 | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' -----------------------------------------------------------------------······· [OK] C:\ulisse\strawberry\perl\bin\perl.exe ----------------------------------------······· | Perl v5.20.0 on MSWin32 arch MSWin32-x86-multi-thread-64int | s1='Hi Thing One' s2='' | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' | Option 1 | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' -----------------------------------------------------------------------······· [OK] C:\ulisse\straw5.20-32b\perl\bin\perl.exe ----------------------------------------······· | Perl v5.16.2 on MSWin32 arch MSWin32-x64-multi-thread | s1='Hi Thing One' s2='' | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' | Option 1 | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' -----------------------------------------------------------------------······· [OK] C:\ulisse\straw64\perl\bin\perl.exe #option 2 ----------------------------------------······· | Perl v5.14.2 on MSWin32 arch MSWin32-x86-multi-thread | s1='Hi Thing One' s2='' | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' | Option 2 | s1='Hi Thing One*Bye Thing One' s2='Hi Thing Two*Bye Thing Two' -----------------------------------------------------------------------······· [OK] C:\ulisse\strawberry\perl\bin\perl.exe ----------------------------------------······· | Perl v5.20.0 on MSWin32 arch MSWin32-x86-multi-thread-64int | s1='Hi Thing One' s2='' | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' | Option 2 | s1='Hi Thing One*Bye Thing One' s2='Hi Thing Two*Bye Thing Two' -----------------------------------------------------------------------······· [OK] C:\ulisse\straw5.20-32b\perl\bin\perl.exe ----------------------------------------······· | Perl v5.16.2 on MSWin32 arch MSWin32-x64-multi-thread | s1='Hi Thing One' s2='' | s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' | Option 2 | s1='Hi Thing One*Bye Thing One' s2='Hi Thing Two*Bye Thing Two' -----------------------------------------------------------------------······· #### option 1 perl c:\ulisse\elisheva-demo01.pl Pe on MSWin32 arch MSWin32-x86-multi-thread s1='Hi Thing One' s2='' s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' Option 1 s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' >echo option 2 option 2 >perl c:\ulisse\elisheva-demo01.pl Pe on MSWin32 arch MSWin32-x86-multi-thread s1='Hi Thing One' s2='' s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' Option 2 s1='Hi Thing One' s2='Hi Thing Two*Bye Thing Two' >perl -v This is perl, v5.8.8 built for MSWin32-x86-multi-thread