in reply to Re^3: best practice when using XML::Parser and strict.
in thread best practice when using XML::Parser and strict.

Really interesting bobf, thanks for such a complete response.

I didn't spot the warnings because the script spews out over a page full of prints almost immediately, but they were there though.

Using the fact the these inner values are rebound in anonymous subroutines, I came up with the followng, but I'm just playing now :-)

Thanks to everyone, this has been really helpful.

use XML::Parser; use strict; parse_stuff(); sub parse_stuff { my $indent; my $parser = new XML::Parser( Handlers => {Start => sub { $indent++; handle_start($indent, @_) + }, End => sub { $indent--; handle_end(@_) } } ); $parser->parsefile('/tmp/ra.xml'); } sub handle_start { my ($indent, $p, $el, %atts) = @_; print "-"x$indent . "$el\n"; } sub handle_end { # whatever }