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

Hello: I am currently designing a data object builder for that extrapolates clinical data from an XML export and imports into a ASCII format. (Oh the joys of a clinical systems analyst.) Anyway, my issue is that my initial procedural format for my code works. I can read the file name, parse it using XML::DOM and spit out something resembling the ASCII format I need. however, whenever I use my new HemoCode:
package CathRecord; require XML::DOM; use strict; use Class::Struct; struct CathRecord => { PatDemo => '@', CathEvents => '%', Procedures => '%', CathStaff => '%', CathBlood => '%', CathEvent => '%', CathSat => '%', CathAldrete => '%', }; 1; sub CamPatDemo { my $file = $_[0]; my $obj = CathRecord->new(); my $parser = XML::DOM::Parser->new(); my $doc = $parser->parsefile($file); my @patdemo; my ($ln, $fn, $sex, $dob, $htu, $htn, $wtu, $wtn, $patnum, $patien +t); #Get Patient Data foreach $patient($doc->getElementsByTagName('SA_PATIENT')) { $ln = $patient->getElementsByTagName('MY_LAST_NAME')->item(0)- +>getFirstChild->getNodeValue; $fn = $patient->getElementsByTagName('MY_FIRST_NAME')->item(0) +->getFirstChild->getNodeValue; $dob = $patient->getElementsByTagName('MY_BIRTH_DATE')->item(0 +)->getFirstChild->getNodeValue; $sex = $patient->getElementsByTagName('MY_GENDER')->item(0)->g +etFirstChild->getNodeValue; $dob = $patient->getElementsByTagName('MY_BIRTH_DATE')->item(0 +)->getFirstChild->getNodeValue; } foreach $patient($doc->getElementsByTagName('CathStudy')) { $htn = $patient->getElementsByTagName('PatHeight')->item(0)->g +etFirstChild->getNodeValue; $wtn = $patient->getElementsByTagName('PatWeight')->item(0)->g +etFirstChild->getNodeValue; $htu = $patient->getElementsByTagName('PatHeight')->item(0)->g +etAttribute('Units'); $wtu = $patient->getElementsByTagName('PatWeight')->item(0)->g +etAttribute('Units'); $patnum = $patient->getElementsByTagName('StudyID')->item(0)-> +getFirstChild->getNodeValue; } @patdemo = [$ln, $fn, $dob, $sex, $dob, $htn, $htn, $wtu, $wtn, $p +atnum]; $obj->{'PatDemo'} = @patdemo; return $obj-{'PatDemo'}; }
I get the following error:
H:\My Documents\HemoKit>perl m6.pl Couldn't open CathRecord=HASH(0x234ee0): No such file or directory at CathRecord.pm line 25
For some reason, my module is unable to accept a string. It keeps referring to my entry as a hash. Here is my input code:
#!/usr/bin/perl -w use XML::DOM; use CathRecord; ### Create New Object my $file = "H:/My Documents/files/mfrTESTa.XML"; my $obj = CathRecord->new(); my @sa = $obj->CamPatDemo($file);
Is it the module or the way I am accessing its attributes. Regards - Cappadonna

Replies are listed 'Best First'.
Re: Attempting to read file name into my XML Parsing Object
by Fletch (Bishop) on Apr 26, 2006 at 18:06 UTC

    When you call a method (class or instance) $_[0] contains the thing the method was called upon. In your case this is $obj, and $_[1] would contain the path you passed as the argument. Your code makes a new instance inside the method itself, then returns that new instance.

    To put it bluntly, you've got some confusion about OO in Perl. See perlboot and the other OO tutorials for more details.

      Cool. I took a little time to look over my Advance Perl Programming Book (the O'Reilly Panther book). I got it working for the most part. However, it appears that I'm having array errors.

      To create a list of hospital staff, my method parse through the staff list and records their first and last name into an array. This array is then reference in a hash, using their role (X-ray Tech, physician, Nurse) as a key.

      foreach $workerbee($doc->getElementsByTagName('CathStaff')) { print "Staff = $s1, $s2\n"; $s1 = $workerbee->getElementsByTagName('LastName')->item(0 +)->getFirstChild->getNodeValue; $s2 = $workerbee->getElementsByTagName('FirstName')->item( +0)->getFirstChild->getNodeValue; $s3 = $workerbee->getAttribute('Role'); @staff = ($s1,$s2); print "Staff = $s1, $s2\n"; my $arrayref = \@staff; $staff_set{$s3} = $arrayref; }

      Now my main loop is this:

      !/usr/bin/perl -w use XML::DOM; use CathRecord; ### Create New Object my $file = "H:/My Documents/files/mfrTESTa.XML"; my $obj = CathRecord->new(); my $ref = CathRecord::CamPatData($obj,$file); print"\n"; my $hashref = $ref->{STAFF}; foreach my $inst(keys %$hashref) { my $aih = $$hashref{$inst}; print "$inst: @$aih\n"; }

      I get this is a result:

      Staff = Joicelan, Rob Staff = Zdoctor, test Staff = Zdoctor, test Staff = Smith, Fred Staff = Smith, Fred Staff = Jones, Bill Staff = Jones, Bill Staff = Nelson, Jim Staff = Nelson, Jim Staff = Fellowlast, Fellowfirst Staff = Fellowlast, Fellowfirst Staff = fellowsecond, fred Staff = fellowsecond, fred Staff = rusoo123456789012, mike56789012345 Circ: rusoo123456789012 mike56789012345 Recording: rusoo123456789012 mike56789012345 Fellow: rusoo123456789012 mike56789012345 Scrub: rusoo123456789012 mike56789012345 Assisting_MD: rusoo123456789012 mike56789012345 Other: rusoo123456789012 mike56789012345 Rad: rusoo123456789012 mike56789012345 Physician: rusoo123456789012 mike56789012345

      So what's up with that?