gjeffrey has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

How do I determine the version of XML::Twig installed on my machine. The top line from "perldoc XML::Twig" says:

.0::XML::Twig(3User Contributed Perl Documentatio.0::XML::Twig(3)
and I am running perl v5.6.0. I want to guess it Twig version 3.XX but I don't know what XX should be.

My immediate challenge my installation cannot do:

$twig->set_doctype(...)

The error is

Can't locate object method "set_doctype" via package "XML::Twig"
Sample Perl Program:
#!/usr/bin/perl use strict; use XML::Twig; my $twig= new XML::Twig(TwigHandlers => { servlet => \&servletTag }, comments => "keep" ); $twig->set_pretty_print( "indented"); # parse the twig $twig->parsefile( "web.xml"); $twig->set_doctype("test", "test", "test", "test"); $twig->print(); sub servletTag { my $LOCALE = "es_US"; my( $twig, $servlet)= @_; my $jspFileTag= $servlet->first_child("jsp-file");; if (defined($jspFileTag)) { my $path = $jspFileTag->text(); my $LOCALE_MOD = "/$LOCALE/"; if ( $path =~ /$LOCALE_MOD/ ) { $servlet->cut(); return; } } }
Sample XML File
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3// +EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <!-- This is my comment --> <web-app> <servlet> <servlet-name>Authenticate_en_US</servlet-name> <jsp-file>/vxml/en_US/type_0/entry/Authenticate.jsp</jsp-file> <load-on-startup>2</load-on-startup> </servlet> <servlet> <servlet-name>Authenticate_es_US</servlet-name> <jsp-file>/vxml/es_US/type_0/entry/Authenticate.jsp</jsp-file> <load-on-startup>2</load-on-startup> </servlet> </web-app>

Replies are listed 'Best First'.
Re: Determining Installed Twig Version
by gellyfish (Monsignor) on Jul 28, 2004 at 14:57 UTC

    To get the version of the module you can do:

    perl -MXML::Twig -e'print $XML::Twig::VERSION'
    This should work with most modules as all are supposed to have $VERSION defined.

    /J\

      This also works and is slightly more functional if the previous version doesn't work. The difference is that if the version isn't declared exactly where you guessed at, this will look around in some other places to find it.

      perl -MXML::Twig -le 'print XML::Twig->VERSION'
Re: Determining Installed Twig Version
by mifflin (Curate) on Jul 28, 2004 at 15:02 UTC
    # perl -MXML::Twig -e'print "$XML::Twig::VERSION\n"'
    3.09
      Thanks. Turns out I have version 2.02 of twig.
Re: Determining Installed Twig Version
by pg (Canon) on Jul 28, 2004 at 15:10 UTC

    Or, to demystify this, just go to your site\lib\XML under your perl home, open up Twig.pm, search for $VERSION, see what value it is set to.