in reply to Using s/// Inline
($key=~m{^\d+$} ? "fid" : "name") => ($key=~m{^\d+$} ? $key : lc($key =~ s/[^a-z0-9]/_/ig))
Do you think that's readable? And you want to add to it? Whoa!
sub add_record { my ($self, $data) = @_; my @record; for my $key (keys %$data) { my $att_key = $key =~ /[^0-9]/ ? "name" : "fid"; ( my $att_val = lc($key) ) =~ s/[^a-z0-9]/_/g; push @record, { tag => "field", atts => { $att_key => $att_val }, value => $data->{$key}, }; } return post_api("API_AddRecord", \@record); }
By the way, don't use prototypes! You didn't even use the right one, so that means you have to bypass it to call your sub!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using s/// Inline
by bichonfrise74 (Vicar) on Nov 16, 2009 at 19:39 UTC | |
by ikegami (Patriarch) on Nov 16, 2009 at 20:00 UTC | |
by Jason Hutchinson (Acolyte) on Nov 16, 2009 at 21:09 UTC | |
by ikegami (Patriarch) on Nov 16, 2009 at 21:27 UTC | |
by bobr (Monk) on Nov 17, 2009 at 13:47 UTC | |
|
Re^2: Using s/// Inline
by Jason Hutchinson (Acolyte) on Nov 16, 2009 at 16:41 UTC |