In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Kim Helliwell) wrote:

> I detect them. If I have an object that represents a phone number
> entry, $phone, I try
> 
> $phone->delete($phone)
> 
> or
> 
> $phone->delete('phone')

Did you try simply:

   $phone->delete;

?

Or, alternatively:

   $address_book->delete($phone);

The latter is the older syntax.  $phone is the direct object that delete() 
takes as its argument, and the relatively newer syntax allows you to move 
the direct object in front, hence $phone->delete.

I tried it, and it works for me:

#!/usr/bin/perl -w
use strict;
use Mac::Glue ':all';

my $address = new Mac::Glue 'Address Book';

my $person = $address->obj(
   person     => 1,
   people     => whose(AND =>
      [ first_name => equals => 'Stevie'  ],
      [ last_name  => equals => 'Wonder' ]
   )
);

my %seen;
for my $phone (reverse $person->prop('phones')->get) {
   my $number = $phone->prop('value');
   # normalize
   (my $string = $number->get) =~ s/\D+//g;
   $string =~ s/^1//;
   print $string;
   if ($seen{$string}++) {
      $phone->delete;
      print ": Deleted";
   }
   print "\n";
}

__END__


Note that I do reverse in the for loop, because if you delete one entry 
before trying to work on the next, the order is messed up and you have an 
invalid object, as the actual AEDesc in each $phone object in that loop 
references an index (phone number 1, phone number 2, etc.).

Cheers,

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to