in reply to Re: prototypes for dual-file handle print?
in thread prototypes for dual-file handle print?
There's no way to define a sub to have the same syntax as print
I always thought function $foo $bar is another notation for $foo->function($bar) (which is also often used to imitate the new operator from other languages). So for example the following works:
use warnings; use strict; my $mp = MyPrint->new(*STDERR); $mp->myprint("foobar\n"); myprint $mp "foobar\n"; package MyPrint; sub new { my ($class, $out) = @_; return bless { out => $out }, $class; } sub myprint { my ($self, $text) = @_; my $out = $self->{out}; print $out $text; }
I don't really know why STDERR->print "foobar" doesn't work though. It dies with
although the documentation says something else.Can't locate object method "print" via package "IO::Handle"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: prototypes for dual-file handle print?
by ikegami (Patriarch) on Jul 06, 2010 at 16:23 UTC | |
|
Re^3: prototypes for dual-file handle print?
by Fletch (Bishop) on Jul 06, 2010 at 15:07 UTC |