in reply to Help with XML::Twig::Gedcom

It is very simple:

my $t = XML::Twig->new( twig_roots => { "IndividualRec[\@Id=\"$individual_id\"]" = +> sub { load_individual( @_, \%hash); } } ); ... sub load_individual { my( $t, $individual, $hashref)= @_; ... }

What you do here is create a closure, but you really don't have to know that! Achieving Closure has more explanations on what happens under the hood.

Replies are listed 'Best First'.
Re^2: Help with XML::Twig::Gedcom
by buttroast (Scribe) on Oct 18, 2004 at 16:36 UTC
    Michael,

    I made the changes you mentioned, and now I get the following error:

    Can't modify string in scalar assignment at /home/tiffanya/public_html/cgi-bin/modules/XML/Twig/Gedcom.pm line 94, near "} }"

    Also, should the %hash variable have our scope and be used in place of all of my $self variables?

    Thanks buttroast

      I don't know what argument you are trying to pass to the handler, so I just put one at random, you will have to replace %hash by your own, there is nothing magic about it. It you need to pass an object, then pass it.

      Using our on the other end would probably defeat the purpose of passing the variable as a parameter.

        Alright, I figured it out. I didn't realize that when you use the ->, it automatically sends the object reference as the first variable in @_. I got it working and really cleaned it up. Thanks for your help!
        Thanks buttroast