pseudomonas has asked for the wisdom of the Perl Monks concerning the following question:
If I try#!/usr/bin/perl use XML::Twig; my $t=XML::Twig->new( twig_handlers => { name => \&my_s }); $t->parse('<doc><name>Alice</name><name>Bob</name></doc>'); sub my_s { my ($twig, $section, $greeting) = @_; print $greeting || "Hello" , ", ", $section->text(), "!\n"; } # Yields: # Hello, Alice! # Hello, Bob!
What am I missing?my $t=XML::Twig->new( twig_handlers => { name => \&my_s("Hi") }); # Can't call method "text" on an undefined value # likewise with &my_s->("Hi")
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing additional arguments to XML::Twig handlers
by Fletch (Bishop) on Jan 29, 2008 at 14:31 UTC | |
by pseudomonas (Monk) on Jan 29, 2008 at 14:45 UTC | |
|
Re: Passing additional arguments to XML::Twig handlers
by mirod (Canon) on Jan 29, 2008 at 14:43 UTC | |
|
Re: Passing additional arguments to XML::Twig handlers
by moritz (Cardinal) on Jan 29, 2008 at 14:33 UTC | |
by pseudomonas (Monk) on Jan 29, 2008 at 14:47 UTC |