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

I am using Carp along with Twig.PM, and I receive this error message, when using parsefile:
Missing base argument at /usr/lib/perl5/site_perl/5.6.0/HTTP/Request.pm line 107
As a test, I try parsing a simple segment of XML with parse, and receive this message:
Can't use string ("<doc><para>para1</para></doc>") as a symbol ref while "strict refs" in use at /usr/lib/perl5/site_perl/5.6.0/i386-linux/XML/Parser/Expat.pm line 456.

These errors only occur when Carp is turned on. Twig itself continues to work despite the error messages. Here's the code:
# aidbrowser.pm package aidbrowser; use CGI; use XML::Twig; BEGIN { $allaids = "FindingAids/"; %FullNames = ( "UMASS" => "University of Massachussetts", "Smith" => "Smith College", "MtHolyoke" => "Mt. Holyoke College", "Amherst" => "Amherst College", "Hampshire" => "Hampshire College", "MortimerRareBookRoom" => "Mortimer Rare Book Room, Smith Col +lege", "SophiaSmithCollection" => "Sophia Smith Collection, Smith Col +lege" ); return bless( { }, shift); } sub printDirs() { my $rets; my $content; opendir(THISDIR, $allaids) or die ("Couldn't open finding aids for +browsing!"); my @dircontents = grep !/^\./, readdir THISDIR; closedir(THISDIR); foreach $content (@dircontents) { if(-e $allaids.$content && -d $allaids.$content) { if($FullNames{$content}) { $rets .= p(h2($FullNames{$content}),br,printAids($content +)); } } } return $rets; } sub printAids() { my $aiddir = shift; my $eadid,$eadtitle,$eadauthor,$eadlastchng; opendir(AIDDIR, $allaids.$aiddir."/"); my @dircontents = grep !/^\./, readdir AIDDIR; closedir(AIDDIR); my $rets; if(!@dircontents) { $rets .= em("No finding aids for this institution are available +at this time."); } else { foreach $aid (@dircontents) { if($aid =~ /(\w+).xml/) { $eadid = $1; $rets .= p($eadid); $eadtitle = getAidTitle($allaids.$aiddir."/".$aid); $rets .= p("Title is $eadtitle"); } } } return $rets; } sub getAidTitle() { my $file = shift; my $twig = new XML::Twig(); $twig->parsefile($file); $elt = $twig->get_xpath("//titleproper",0) or "No title"; $elt = $twig->get_xpath('/ead/eadheader/filedesc/titlestmt/titlepro +per',0) or "Invalid title"; $text = $elt->text; $text=~ s/(^\s*|\s*$)//g; return $text; } sub browsingMenu() { return h1("Select a finding aid to open"), printDirs(); } 1;

Replies are listed 'Best First'.
Re: Twig.PM and parsing
by mirod (Canon) on Aug 06, 2001 at 20:06 UTC

    Somehow I doubt the problem comes from XML::Twig. I have extracted the getAidTitle function and run it on test XML data... and it works fine, except of course I get a warning for your use of or "No title", which I guess used to be a croak "No title", and another one on the next line.

    Do you also have the same problem if you replace the entire getAidTitle by a constant?

    One last remark: you should use strict; at the top of your code, it would catch most typos in variable names.

      If I replace the title with a constant, it works out
      fine... The error happens when I call parse or parsefile.
Re: Twig.PM and parsing
by LD2 (Curate) on Aug 06, 2001 at 19:57 UTC