Created
July 9, 2012 11:23
-
-
Save xaicron/3075900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Foo::Handle; | |
use strict; | |
use warnings; | |
sub TIEHANDLE { | |
my ($class, $handle) = @_; | |
bless \$handle, $class; | |
} | |
sub PRINT { | |
my ($self, $buff) = @_; | |
$buff .= $\; # if omit this line then restore $\. | |
} | |
package main; | |
use strict; | |
use warnings; | |
use feature 'say'; | |
use Symbol qw(gensym); | |
open my $fh, '>', 'FOO'; | |
printf "[%s]\n", $\; | |
say $fh 'foo'; | |
printf "[%s]\n", $\; # $\ is restored | |
my $gh = gensym; | |
tie *$gh, 'Foo::Handle'; | |
printf "[%s]\n", $\; | |
say $gh 'foo'; | |
printf "[%s]\n", $\; # $\ is not restored (it's bug?) | |
__END__ | |
$ ./foo.pl | |
Use of uninitialized value $\ in printf at foo.pl line 23. | |
[] | |
Use of uninitialized value $\ in printf at foo.pl line 25. | |
[] | |
Use of uninitialized value $\ in printf at foo.pl line 29. | |
[] | |
[ | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment