Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created July 9, 2012 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xaicron/3075900 to your computer and use it in GitHub Desktop.
Save xaicron/3075900 to your computer and use it in GitHub Desktop.
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