Palm:PDB and arrays and hashes problem.

Palm:PDB and arrays and hashes problem.

am 08.01.2005 23:42:46 von p cooper

im using palm:PDB to read information from a database
(http://sourceforge.net/projects/pilot-db/).
I set up a DB to test
2 fields, 2 rows
Date|Number
8jan|1
9jan|2

#! /usr/bin/perl -w
use strict;
use Palm::PDB;
use Palm::Raw;
use Data::Dumper;

my $pdb = new Palm::PDB();


Palm::PDB::RegisterPDBHandlers("Palm::Raw", "");

$pdb->Load("OR2.pdb");

@array =$pdb->{"records"};
print "@array";

gives ARRAY(0x81f8a28)
-----------------------
then
@array =$pdb->{"records"};
foreach $array_element(@array)
{print "$array_element \n" ;
}
gives ARRAY(0x81f89d8)
----------------------------------
print $pdb->{"records"}->[0];

gives HASH(0x81aec9c) (bit closer!!!)
--------------------------------------
print $pdb->{"records"}->[0]->{'Number'} (or Date);

gives Use of uninitialized value in print......
------------------------------------
print $pdb->{"records"}->[0]->[0];

gives Not an ARRAY reference at palm.pl line 86.

---------------------------------------
print ${@array}[0];
and Im back to the array.

ve read the chapter 11 in perl cookbook - hence ive got this far.

I dont know how to get at individual fields of each row in the database
a hash ? what are the keys ?
an array ? - so why does it tell me I have a hash?

Thanks for any pointers

Re: Palm:PDB and arrays and hashes problem - a bit further ....

am 09.01.2005 17:00:21 von p cooper

@array =$pdb->{"records"};
#print @$array;

print Dumper \@array;


gives
$VAR1 = [
[
{
'data' => 1',
'id' => 13180929,
'category' => 0,
'attributes' => {
'Dirty' => 1,
'dirty' => 1
},
'offset' => 138
},
{
'data' => Õ 2',
'id' => 13180930,
'category' => 0,
'attributes' => {
'Dirty' => 1,
'dirty' => 1
},
'offset' => 148
}
]
];


anyone know what to do next ????

Re: Palm:PDB and arrays and hashes problem.

am 10.01.2005 22:09:19 von Jim Gibson

In article , p cooper
wrote:

> im using palm:PDB to read information from a database
> (http://sourceforge.net/projects/pilot-db/).
> I set up a DB to test
> 2 fields, 2 rows
> Date|Number
> 8jan|1
> 9jan|2
>
> #! /usr/bin/perl -w
> use strict;
> use Palm::PDB;
> use Palm::Raw;
> use Data::Dumper;
>
> my $pdb = new Palm::PDB();
>
>
> Palm::PDB::RegisterPDBHandlers("Palm::Raw", "");
>
> $pdb->Load("OR2.pdb");
>
> @array =$pdb->{"records"};
> print "@array";
>
> gives ARRAY(0x81f8a28)
> -----------------------
> then
> @array =$pdb->{"records"};

You want my @array = @{$pdb->{"records"}} according to the
documentation, so $pdb->{"records"} is returning a reference to an
array. The documentation does not specify the type of the elements of
this array, however. You should probably try:

my $array_ref = $pdb->{"records"};
print Dumper($array_ref);

> foreach $array_element(@array)
> {print "$array_element \n" ;
> }
> gives ARRAY(0x81f89d8)
> ----------------------------------
> print $pdb->{"records"}->[0];
>
> gives HASH(0x81aec9c) (bit closer!!!)

So close! Try (untested):

print join("\n",keys $pdb->{"records"}->[0]), "\n";

or better yet:

foreach my $key ( sort keys $pdb->{"records"}->[0] ) {
print "$key: ${$pdb->{"records"}->[0]}\n";
}


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Re: Palm:PDB and arrays and hashes problem - a bit further ....

am 10.01.2005 22:22:17 von Jim Gibson

In article , p cooper
wrote:

> @array =$pdb->{"records"};
> #print @$array;
>
> print Dumper \@array;
>
>
> gives
> $VAR1 = [
> [
> {
> 'data' => 1',
> 'id' => 13180929,
> 'category' => 0,
> 'attributes' => {
> 'Dirty' => 1,
> 'dirty' => 1
> },
> 'offset' => 138
> },
> {
> 'data' => Õ 2',
> 'id' => 13180930,
> 'category' => 0,
> 'attributes' => {
> 'Dirty' => 1,
> 'dirty' => 1
> },
> 'offset' => 148
> }
> ]
> ];
>
>
> anyone know what to do next ????

Not really, since you haven't described what you want to do, but I am
pretty sure that

${$array}[0]}[0]->{'data'} has the value 1. :)


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Re: Palm:PDB and arrays and hashes problem - a bit further ....

am 11.01.2005 01:08:55 von Jim Gibson

In article <100120051322178045%jgibson@mail.arc.nasa.gov>, Jim Gibson
wrote:

> In article , p cooper
> wrote:
>
> > @array =$pdb->{"records"};
> > #print @$array;
> >
> > print Dumper \@array;
> >
> >
> > gives
> > $VAR1 = [
> > [
> > {
> > 'data' => 1',
> > 'id' => 13180929,
> > 'category' => 0,
> > 'attributes' => {
> > 'Dirty' => 1,
> > 'dirty' => 1
> > },
> > 'offset' => 138
> > },
> > {
> > 'data' => Õ 2',
> > 'id' => 13180930,
> > 'category' => 0,
> > 'attributes' => {
> > 'Dirty' => 1,
> > 'dirty' => 1
> > },
> > 'offset' => 148
> > }
> > ]
> > ];
> >
> >
> > anyone know what to do next ????
>
> Not really, since you haven't described what you want to do, but I am
> pretty sure that
>
> ${$array}[0]}[0]->{'data'} has the value 1. :)

Actually, I am not so sure any more. In my newsreader, the value of
${$array}[0]}[0]->{'data'} is a 1 followed by a single quote, which is
invalid Perl. The value of ${$array}[0]}[1]->{'data'} has a funny
character in it. Since these are called 'data', I suspect they contain
some sort of binary data. Hopefully, you will have figured out by now
how to access all of the data.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---