Eric on 16 Jun 2007 17:37:41 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

data structure / reference question


Good day!

It's been a while since I had to do any semi-serious data structures,
especially in perl, and I'm having trouble.  I never was a data structure
wiz but perl seems to make it harder to understand.  Perhaps I'm just
doing it using one of the TMTOWTDI ways that actually does not do it!

Here's what's up:

I have a account id with multiple values like this:

  FILESYSTEM
     +-------   account00
                    +-------   filename01  --  filenumber01
                    +-------   filename02  --  filenumber02
                        .
                        .
                    +-------   filenameNN  --  filenumberNN
         .
         .
     +-------   accountNN

Since I want to compare these with a similar structure
from a database I'd actually have another one:

 DATABASE
     +-------   account00
                    +-------   filename01  --  recordnumber01
                    +-------   filename02  --  recordnumber02
                        .
                        .
                    +-------   filenameNN  --  recordnumberNN
         .
         .
     +-------   accountNN


I'll need to compare them by matching the account numbers, then the
filenames.

   If they match it's okay.
   If there is a file and no database entry then I create one and
      store the filename and filenumber.
   If there is a database entry and no corresponding account/filename
      then I delete the file.


My idea is to loop over the file information and create hashes
like this:
    $ACCOUNTS{$accountnum}{$filename}{"NAME"} = $filename ;
    $ACCOUNTS{$accountnum}{$filename}{"NUMBER"} = $filenumber ;

and this for the database values:
    $DATABASE{$accountnumber}{$filename}{"RECORDNUMBER"} = $recordID ;

I'd want to compare the account numbers and filenames if they exist.
How do I see the filename?  I can see the account number like this:

foreach $key ( keys %ACCOUNTS ) {
  print "ACCOUNT is: $key  and file name is: " . $ACCOUNT{$key} ."\n" ;
}

The $key value contains the account number but $ACCOUNT{$key} won't
dereference and get the file name.  Do I need another foreach loop
inside the first one?  I tried this:

foreach $key ( keys %ACCOUNT ) {
  foreach $innerkey ( keys %{$ACCOUNT{$key}} ) {
    print "ACCOUNT is: $key and the filename is: " . $innerkey   . "\n" ;
  }
}

That code prints nothing although I know there is data in there :-)

Insight would be greatly appreciated!

Thanks,
Eric
-- 
------------------------------------------------------------------------
#  Eric A Lucas
#     "Oh, I have slipped the surly bond of earth
#      And danced the skies on laughter-silvered wings...
#                             -- John Gillespie Magee Jr.
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**