Re: accessing object variables from callback function



kaisung@xxxxxxxxx schreef:

package MyTest;

Missing:

use strict ;
use warnings ;

use XML::Parser;

# Create a new object
sub new { [...]
}

# Load an xml file and count the number of tags
sub load { [...]
}

# Return the number of tags in loaded xml file
sub numTags { [...]
}
[...]
1;
-----END MyTest.pm-----

-----BEGIN mytest.pl-----
#!/usr/bin/perl -w

Missing:

use strict ;

If your perl is not very old, replace the -w (in the shebang) by the
lexical

use warnings ;


use MyTest;

my $test = MyTest->new();

Variant:

my $test = new MyTest ;


$test->load("test.html");
print "numTags = " . $test->numTags() . "\n";


Variant:

$test->load('test.html') ;
print "numTags = @{[ $test->numTags() ]}\n" ;

or even:

print "numTags = $test->{numTags}\n" ;

(which bypasses the method)


--
Affijn, Ruud

"Gewoon is een tijger."


.



Relevant Pages

  • Re: vb functions evaluating on load
    ... Sub get_xml ... But instead of this function waiting for the button to fire the event on the onserverclick, it runs it on load, so it goes and fetches xml before the user has even entered an xml file in a field. ... > Are you saying the Page_Load is run before your event handler is firing? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: RecLength for Random File
    ... Firstly have a look at your routine Public Sub Load. ... Public MyRec As Fields ' Record variable ... The stuff you have written belongs in the (declarations) section of your Form. ...
    (microsoft.public.vb.general.discussion)
  • Re: UserForm Is A Class
    ... assume the using "Load" is the correct in a situation like your example. ... Load myForm ... > Private Sub UserForm_Activate ... > Private Sub UserForm_Deactivate ...
    (microsoft.public.word.vba.general)
  • Re: Does loading additional forms drain resources?
    ... I also hadn't thought of loading a tab's subform until you click on the tab. ... One great tip is to not load sub forms until you need them. ...
    (microsoft.public.access.forms)
  • Re: Does loading additional forms drain resources?
    ... costs is your additional coding and developer time. ... One great tip is to not load sub forms until you need them. ... loads only ONE sub-form loads (the one on the 1st tab). ...
    (microsoft.public.access.forms)