in reply to Re: XML::XPath and processing multiple files
in thread XML::XPath and processing multiple files

My apologies for not being complete. The file list is a manually created list of selected file paths. As far as whether or not they exist - if I pair the list down to just the first file - the script works fine. Here is the entire script:
use XML::XPath; use XML::XPath::XMLParser; my $filelist = shift; #Process file list open(FILELIST, "$filelist") or die("Unable to open file"); my @files = <FILELIST>; close(FILELIST); foreach $page (@files) { my $xp = XML::XPath->new(filename => $page); my $nodeset = $xp->find('//DCR'); # find all DCRs my @nodelist = $nodeset->get_nodelist; #@dcrs = map($_->string_value, @nodelist); @dcrs = map {$_->string_value ? $_->string_value : ()} @nodeli +st; foreach my $dcr(@dcrs) { print "$dcr\n"; } }
For some reason I thought I'd added chomp before and it didn't work:
chomp($page);

Replies are listed 'Best First'.
Re^3: XML::XPath and processing multiple files
by Corion (Patriarch) on Jul 15, 2013 at 14:48 UTC

    Most likely there is other whitespace at the end of your file names. Or maybe the "first" file exists in two places.

    Does the script still fail if you have the line with the first, existing file duplicated?

      Yes it does fail with the first duped. It only works when there is one file in the list. Weird I know.

        Now maybe is the time to investigate the difference between the two values.

        Have you printed out their length? Have you compared their values as Perl perceives them?

        ... my $last_page; foreach my $page (@files) { warn "Now opening different page."; warn "Old: [$last_page] New: [$page]"; warn sprintf "Length: Old: %d New: %d", length $last_page, length +$page; warn "They are " . ($last_page ne $page ? "not" : "" ) . " equal"; my $xp = XML::XPath->new(filename => $page); $last_page= $page; ... };
Re^3: XML::XPath and processing multiple files
by poj (Abbot) on Jul 15, 2013 at 15:36 UTC
    chomp may not work if the filelist was manually created on a windows machine and you are running the script on unix. Suggest you try a regex instead.
    open(IN,'file.txt') or die "$!"; my @files = <IN>; foreach $page (@files) { $page =~ s/\s+$//g; print "parsing [$page]\n"; # code }
    poj
Re^3: XML::XPath and processing multiple files
by ATLien (Initiate) on Jul 15, 2013 at 14:50 UTC
    Also the complete error is:

    Cannot open file 'file1.xml ' at /apps/interwoven/TeamSite/iw-perl/vendor/lib/XML/XPath.pm line 53.

      Did you note the whitespace between the .xml and the trailing apostrophe in the error message? Maybe your file names do not end with whitespace in the extension?

        That was due to a multi-line copy from Putty. :)