in reply to examples using Palm::Addressbook?

fractureMech,
Ok - I don't own a Palm Pilot, but I think this will work. With statements from the POD like "I don't know what these are.", I have to agree with your assesment of the documentation. You might also want to take a look at pdbdump which comes with the p5-Palm-1.3.0 suite
#!/usr/bin/perl -w use strict; use Text::CSV; use Palm::PDB; use Palm::Address; my $pdb = new Palm::PDB; $pdb->Load("myfile.pdb") or die "Unable to attach to address book"; my $csv = Text::CSV->new(); my @order = qw( name firstName company phone1 phone2 phone3 phone4 phone5 address city state zipCode country title custom1 custom2 custom3 custom4 note ); open (OUTPUT, ">address.csv") or die "Unable to open output file : $!" +; select OUTPUT; for my $record (@{$pdb->{records}}) { my @output; for my $field (@order) { if (exists $record->{fields}{$field}) { push @output, $record->{fields}{$field}; } else { push @output, ''; } } if ($csv->combine(@output)) { my $string = $csv->string; print $string, "\n"; } else { my $err = $csv->error_input; print STDOUT "combine() failed on argument: ", $err, "\n"; } }

Cheers and I hope it helps - L~R

Replies are listed 'Best First'.
Re: Re: examples using Palm::Addressbook?
by fractureMech (Initiate) on Sep 08, 2003 at 01:48 UTC
    I get a lot of error messages saying:
    Use of uninitialized value in ... at C:/Perl/site/lib/Palm/PDB.pm line + ...
    when I run your script. I tried looking at pdbdump, but I can't understand it well enough to simplify it. It works and picks out the records, but the format isn't what I want.
      fractureMech,
      Ok - I was working completely blind there since I don't have a Palm myself. The docs as you have noticed are poor and that is all I had to go on. I will install the module and create a brand new PDB and then work backwards, trying to read my records back in after the fact. I will /msg you when I am complete and update this node.

      Cheers - L~R

      Update: After messing around I was able to create a PDB without the use of a Palm Pilot and read it back in. I am not sure what your problem is, so I will either need a copy of your PDB, or would need you to execute the following piece of code and tell me what you get:

      #!/usr/bin/perl -w use strict; use Palm::PDB; use Palm::Address; use Data::Dumper; my $pdb = new Palm::PDB; $pdb->Load("myfile.pdb") or die "Unable to attach to address book"; my $record = $pdb->{records}[0]; print Dumper($record);
        A much simpler example program is here: http://sourceforge.net/projects/webpdb/ I get the same errors when I cut down the above script to be (as a first step):
        #!/usr/bin/perl -w #use strict; use Palm::PDB; use Palm::Address; my $p = new Palm::PDB; $p->Load( $ARGV[0] ) || die "Error loading $ARGV[0]\n"; my @categories = @{$p->{appinfo}{categories}}; for my $catid (@categories ) { my $cat = $categories[$catid]; if( $cat->{name} ) { print "$cat->{name}\n"; } for my $rec ( sort { $a->{fields}->{name} cmp $b->{fields}->{name} | +| $a->{fields}->{firstName} cmp $b->{fields}->{firstName} } @{ $p->{r +ecords} } ) { print "$rec->{fields}->{firstName} $rec->{fields}->{name}\n"; } }