print {$parser->{parameters}[( exists $attr->{':userID'} ? 0 : 1 )]} $parser->ToXML( $tag, $attr); #### print {$parser->{parameters}[( (exists $attr->{':contents'} and exists $attr->{':contents'}{':userID'}) ? 0 : 1 )]} $parser->ToXML( $tag, $attr); #### use strict; use warnings; no warnings 'uninitialized'; use XML::Rules; my $parser = XML::Rules->new( rules => { _default => 'raw', '^start_element' => sub { my ($tag,$attr,$context,$parents,$parser) = @_; $parser->{pad}{found_userID} = 0; return 1 }, userID => sub { my ($tag,$attr,$context,$parents,$parser) = @_; $parser->{pad}{found_userID} = 1; return [$tag => $attr] }, start_element => sub { my ($tag,$attr,$context,$parents,$parser) = @_; print { $parser->{parameters}[ $parser->{pad}{found_userID} ] } $parser->ToXML( $tag, $attr), "\n"; } } ); open my $FH1, '>', 'c:\temp\test1.xml'; open my $FH2, '>', 'c:\temp\test2.xml'; print $FH1 "\n"; print $FH2 "\n"; $parser->parse( \*DATA, [$FH1, $FH2]); print $FH1 "\n"; print $FH2 "\n"; __DATA__
1
MyChild
2
MyChild MyUser
3
MyChild
##
## my $FH; if (exists $attr->{':user_id'}) { $FH = $parser->{parameters}[0]; } else { $FH = $parser->{parameters}[1]; } print $FH $parser->ToXML( $tag, $attr);

The other script works differently. In the '^start_element' handler it resets the flag (stored in $parser->{pad} which is an attribute of the parser specificaly "to put anything you want to and access it in any handler"), then if the <userID> tag is encountered the flag is set and then the 'start_element' handler selects one of the filehandles passed to $parser->parse()