Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl and Palm Files

by Ryszard (Priest)
on Feb 03, 2002 at 21:45 UTC ( [id://143109]=perlquestion: print w/replies, xml ) Need Help??

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

I've downloaded this palm module from cpan and it seems to work really well thus far. Using these modules i've migrated all my address/dates et al into an SQL database which is a pretty cool thing.

I was wondering if anyone has had any experience in doing a data conversion the other way. ie i want to get my dates/addresses and turn them into a palm file.

I would like to point out that I have RTFM and all that, (and cut some code) and am simply looking for extra experience (traps, pitfalls et al) that anyone may have doing this.

Replies are listed 'Best First'.
Re: Perl and Palm Files
by Beatnik (Parson) on Feb 03, 2002 at 22:22 UTC
    I've been toying with P5::Palm for a while (even posted a few, broken scripts here)... The trick is to read the StdAppInfo POD properly... It contains stuff like ID number, category etc. If you want your data to be handled as Palm data, I suggest you look into that. Data::Dumper helped me to understand how exactly the Palm data structure was used by p5::Palm.
    #!/usr/bin/perl use strict; use Palm::Memo; use Data::Dumper; open(FOO,">foo"); my $pdb = Palm::Memo->new(); $pdb->Load("MemoDB.pdb"); #Load a memo print FOO Dumper $pdb; #Dump the entire structure into a file close(FOO);
    I've been working on a similar project for some time now... I currently have my Datebook, Addressbook, Memos and Todo list online... I'll release it thru Sourceforge in the near future. If you want a link or a lookie at some code, lemme know.

    Update:This is some basic data adding code for Palm::Memo (part of p5::Palm)
    #!/usr/bin/perl use strict; use Palm::Memo; my $pdb = Palm::Memo->new(); $pdb->Load("MemoDB.pdb"); my $record = $pdb->new_Record; $record->{data} = "Foo\nBar\nBaz"; $record->{id} = int rand 65535; $pdb->append_Record($record); $pdb->Write("MemoDB.pdb"); #Warning: The original MemoDB will be overwritten here #I tested this on POSE, since my Palm was out of reach :)

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: Perl and Palm Files
by hossman (Prior) on Feb 03, 2002 at 22:27 UTC
    I believe the CPAN palm module lets you create empty Palm::PDB objects (the super class of each specific type of database), populate them, and write them back out to disk. Take a look at perldoc Palm::PDB.

    As a secondary point: You're post didn't specificly mention that you wanted to sync these databases with a handhelded, but assuming you do, keep in mind that just creating a .pdb is only half the battle. Unless your conduit understands what's going on, you could find yourself adding duplicate records, or blowing away data entered manually on the handheld.

    "Syncing" happens in the conduits themselves, and each conduit decides how to handle merging, so instead of writting a script to generate a .pdb from some data, and then worrying about how your syncing conduit will deal with it, you might just wnat to write a conduit that imports the data directly.

    If you're developing on Unix, your HotSyncing program is probably built on top of pilot-link -- the www site has lots of links with information on writting conduits.

      He actually mentions he exported/imported his addresses and dates, those formats are supported by p5-Palm. If those files are synced (with pilot-link or whatever he uses, you can easily grab the files.

      As long as the ID is unique (well, randomly enough), I see no problem in generating new records. The updated code listed above can be used as a framework for any of the PDB types p5-Palm supports :)

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
      Thanks for the tip hossman.

      My application is web based, and will allow for the uploading of an (address|date|et al).pdb for the migrating of the data into an sql database, and will also allow for the downloading of a .pdb file (ie it will be created from scratch via an SQL database).

      I havent put much too much thought into duplicate records yet.. perhaps i'll use store an MD5 (or sha1) of the record in the database.

      I guess i've got a lot more thinking/planning to do.

        Palm handles duplicate records thru IDs... (see my above listed code on adding a record). If you have the ID in the SQL DB (like I did on my project), and you make that field the unique record key, you can trap any duplicates from being added.

        In other words, a record is only duplicate if you consider it duplicate :)

        Greetz
        Beatnik
        ... Quidquid perl dictum sit, altum viditur.
Re: Perl and Palm Files
by johanvdb (Beadle) on Feb 05, 2002 at 11:34 UTC
    Hi, I've has some fairly good experiences with the p5-Palm modules. I've written up some applications with it. The most complex one can be found on my site. Anyway ... what you'll want to look into is the Palm::PDB and the Palm::Raw modules. An outline of what you need to do is the following ...:
    use Palm::PDB; use palm::Raw; use constant PDB_NAME => 'TimesheetDB'; # the name use constant PDB_TYPE => 'data'; # just data use constant PDB_CREATORID => 'TiSh'; # get one from Palm use constant PDB_VERSION => 261; # just a version number use constant PDB_MODIFICATION => 350; # a mod number use constant PDB_BASEID => 14360577; # you can leave this blank my $PDB = Palm::Raw->new(); $PDB->{"name"} = PDB_NAME; $PDB->{"type"} = PDB_TYPE; $PDB->{"creator"} = PDB_CREATORID; $PDB->{"attributes"}{"backup"} = 1; $PDB->{"version"} = PDB_VERSION; $PDB->{"modnum"} = PDB_MODIFICATION; my $record = $PDB->new_Record; $record->{"data"} = 'anything you want in here'; $record->{"id"} = $id++; # can do that ... do not need to $PDB->append_Record( $record ); $PDB->Write($filename);
    So, this just generates the PDB, no you'll want to synchronise it also ... an execellent way to do is to use the coldsync package. Actually the p5-Palm utilities are from the creator of the coldsync package. You can have conduits (like in hotsync) completely written in Perl. You also can synchronise from you cradle, using Ir or doing fancy stuff like a network hotsync over a modem ...

    Perl is actually a nice fit for writing conduits, as the real challenge is to talk to a system that needs to store the data entered on a Palm. Perl is the ultimate system integration language anyway ;-)

    regards, Johan
      Johan, nice example to start with. I'm just starting in Palm programming and are using perl to retrieve data from a SQL Server. You are talking about sychronization and a way to do that using coldsync. Can you perhaps shoot me some example perl conduits. Very simple ones to start with. Thanks in advance.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://143109]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-29 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found