| 1 | #!/usr/bin/perl | ||
| 2 | use BBDB; | ||
| 3 | |||
| 4 | |||
| 5 | ######################################################################## | ||
| 6 | # Run through a bbdb file and collect all the unique names | ||
| 7 | # in the notes field and print them out seperated by spaces | ||
| 8 | ######################################################################## | ||
| 9 | my %notes; | ||
| 10 | my $bbdb; | ||
| 11 | my $all = BBDB::simple("sample_data.bbdb"); | ||
| 12 | foreach $bbdb (@$all) { | ||
| 13 | my $notes = $bbdb->part('notes'); | ||
| 14 | next unless @$notes; | ||
| 15 | my @fields = map { $_->[0] } @$notes; | ||
| 16 | @notes{@fields} = 1; | ||
| 17 | } | ||
| 18 | print join(' ',keys %notes),"\n\n"; | ||
| 19 | |||
| 20 | ######################################################################## | ||
| 21 | # Run through the bbdb file and print out everybody that has | ||
| 22 | # a mailing address in a "standard" mailing label like format | ||
| 23 | ######################################################################## | ||
| 24 | sub printif { | ||
| 25 | my $s = shift; | ||
| 26 | print "$s\n" if $s; | ||
| 27 | } | ||
| 28 | |||
| 29 | foreach $bbdb (@$all) { | ||
| 30 | my $i; | ||
| 31 | for ($i=0; $i < @{$bbdb->part('address')}; $i++) { | ||
| 32 | my $address = $bbdb->part('address')->[$i]; | ||
| 33 | if ($address->[0] eq 'mailing' ) { | ||
| 34 | printf "%s %s\n",$bbdb->part('first'),$bbdb->part('last'); | ||
| 35 | map { printif $_ } @{$address->[1]}; | ||
| 36 | printf "%s, %s, %s\n%s\n",@$address[2..5]; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | ######################################################################## |