when Perl goes bad
my @tags = sort grep /^(HOME|WORK)$/, map { my ( $i ) = $_ =~ /(\d+)/; uc( $phonelabels[$i - 1] )} grep /^phone/, keys %{$record->{fields}};
I’m still giggling at this.
update: in case anyone’s sufficiently curious: I am tooling around (again) with the Palm addressbook. It has some odd rules for generating the vCards that it beams, one of which revolves around whether the record you’re dealing with has a phone number tagged as "home", one tagged as as "work", neither, or both. The above disaster pulls out the phone numbers, checks their categories, and generates an array of 0, 1 or 2 elements - neither tag exists, one or other tag exists, or both tags exist. Previously I’d done this with a loop and all sorts of readable code, but hey. Sometimes I get a bit silly.
I’m still giggling at this.
update: in case anyone’s sufficiently curious: I am tooling around (again) with the Palm addressbook. It has some odd rules for generating the vCards that it beams, one of which revolves around whether the record you’re dealing with has a phone number tagged as "home", one tagged as as "work", neither, or both. The above disaster pulls out the phone numbers, checks their categories, and generates an array of 0, 1 or 2 elements - neither tag exists, one or other tag exists, or both tags exist. Previously I’d done this with a loop and all sorts of readable code, but hey. Sometimes I get a bit silly.
