waider: (Default)
waider ([personal profile] waider) wrote2005-07-30 03:29 pm
Entry tags:

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.

Post a comment in response:

This account has disabled anonymous posting.
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org