On Wed, May 18, 2011 at 10:37 PM, Kenneth Wolcott <kennethwolc...@gmail.com>wrote:
> Hi; > > A colleague claims that he made no changes, code worked yesterday and > doesn't today. > > He is not using OO Perl. > > I have asked him for a small code snippet that reproduces the error (I'm > sure he is unwilling to show the entire code!). > > We have rules requiring the standard use of "use strict" and "use > warnings" in all our Perl scripts. > > We use Perl on Windows, Linux and Solaris (all his scripts are supposed to > run without modification on Linux and Windows). > > He claims this: "use strict; use warnings; use XML::XPath;" > > Trying to get value for: > $ha = $xPath->findnodes('//job'); > > Error: > Can't call method "findnodes" on unblessed reference at <file_name> line > <line_number>. > > Output from Data::Dumper follows: > > $VAR1 = { > 'object' => [ > { > 'objectId' => 'job-21461', > 'job' => { > 'priority' => 'normal', > 'status' => 'completed', > 'outcome' => 'success', > 'jobName' => 'DeleteBuilds-200911060000', > 'jobId' => > '21461', > 'lastModifiedBy' => 'admin', > } > }, > > { > > 'objectId' => 'job-21473', > 'job' => { > 'priority' => 'normal', > 'status' => 'completed', > 'outcome' => 'success', > 'jobName' => 'DeleteBuilds-200911070000', > 'jobId' => '21473', > 'lastModifiedBy' => 'admin', > } > }, > ] > } > Hi Kenneth, I think the error is clear on what is going wrong: *Error: Can't call method "findnodes" on unblessed reference at <file_name> line <line_number>.* * * When you colleague calls: $xPath->findnodes('//job'); Perl tels him that $xPath is not an blessed reference. In human speak it means he at some point said $xPath = new XML::XPath->new(filename =><filename> ); and this call failed... or he might have assigned a value to $xPath destroying XPath the object that it was holding before. Now lets assume your colleague isn't that silly that he would reassign $xPath my guess is that the file cannot be read, does not exist or maybe is locked. I suspect that your colleague is not wrong the code didn't change but the environment did and now the Perl script does not have rights to read the file. Hope that helps, Rob ps, you might want to besides the rules to always use strict and warnings also implement a rule that before opening of a file one always checks if it exists, and can be opened for the purposes you need it for (read only will not do if you want to write to it) also enforce a simple check to see if the new module::xyz call actually did what was expected from it.