Take this sub routine for example:
sub OnInit {
my( $this ) = @_;
my $frame = Wx::Frame->new( undef, -1, 'wxPerl',
wxDefaultPosition, [ 200, 100 ] );
$frame->{TXT} = Wx::TextCtrl->new( $frame , -1, '');
$frame->Show( 1 );
download( $frame, "http://cpan.org/modules/
01modules.index.html" );
}
'->' is one of the dereference operators (see perlreftut and perlref).
One of its uses is to call methods (see perlboot). This form is often
spelled '.' in other languages (Java and JS, for instance).
> Take this sub routine for example:
>
> sub OnInit {
> my( $this ) = @_;
>
> my $frame = Wx::Frame->new( undef, -1, 'wxPerl',
> wxDefaultPosition, [ 200, 100 ] );
This is a call to the 'new' method of the Wx::Frame class. You would
need to look at the documentation for Wx::Frame to see what that does.
> $frame->{TXT}
This assumes $frame contains a ref to a hash, and returns the "TXT"
member of that hash.
> $frame->Show( 1 );
This assumes $frame contains an object, and calls the 'Show' method of
that object. You would need to look at the documentation for whatever
class $frame belongs to (Wx::Frame in this case) to see what that does.
Ben
The '->' is a way of dereferencing a reference. It can be used in
several ways (that I can think of):
1. Deferencing a reference to a hash or array:
$hashref->{key} is equivalent to ${$hashref}{key}
2. Dereferencing a call to a subroutine:
my $subref = sub { print "$1\n"; };
$subref->('Print this');
3. Calling object methods (objects are blessed references):
$frame->Show(1);
4. Callign package functions:
my $frame = Wx::Frame->new( undef, ... );
which is (almost) equivalent to:
my $frame = Wx::Frame::new( Wx::Frame, undef, ... );
i.e., the package is the first argument passed to the new() function.
Your example has 3 of these 4 uses.
--
Jim Gibson
er, prefer Wx::Frame::new(Wx::Frame::, ...) if you must. Wx::Frame
might refer to function Frame in package Wx. The trailing :: also
implicitly quotes, iirc.
--
"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe"