I think your version is butchering array references, and it
doesn't handle scalar references. I think this works:
sub mychomp {
while (@_) {
for (shift) {
ref or (eval { chomp if defined }, last);
ref eq 'SCALAR' and (eval { chomp $$_ if defined $$_ }, last);
ref eq 'ARRAY' and (do { push @_, map \$_, @$_ }, last);
ref eq 'HASH' and (do { push @_, map \$_, values %$_ }, last);
}
}
}
Question, though, why are we eval'ing the scalar chomps?
chomp warns on undef, but does it fail under some condition? (update: I think I answered my own question...its
for constant values which can't be
chomped).