On Tue, Nov 30, 2010 at 1:31 PM, Rob Dixon <rob.di...@gmx.com> wrote: > The form > > print FILEHANDLE LIST > > is actually 'indirect object' syntax for > calling the print method of the IO::Handle object FILEHANDLE. This is from > 'perldoc perlobj': *snip* > So you can, if you like, use the more usual arrow syntax for calling the > method.
I've been wondering about this syntax and wanted to thank Rob Dixon for explaining it. :) I just tested it out and was amazed at just how easily I made a working example (with no prior experience writing modules or object-oriented Perl). ./Foo/Bar.pm: use strict; use warnings; package Foo::Bar; sub create { my $this = shift; my $class = ref($this) || $this; my ($fh) = @_; my $self = { fh => $fh }; bless $self, $class; return $self; } sub baz { my $this = shift; my (@args) = @_; print { $this->{fh} } @args; } 1; __END__ ./test.pl: #!/usr/bin/env perl use strict; use warnings; use Foo::Bar; my $bar = Foo::Bar->create(\*STDOUT); $bar->baz("This was a triumph.\nI'm making a note here."); baz { $bar } " HUGE SUCCESS.\n"; __END__ Output: This was a triumph. I'm making a note here. HUGE SUCCESS. Fancy. :) -- Brandon McCaig <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/