in reply to chomp any data structure recursively

I thought I would comment because not one of the solutions given handle a reference to a reference. So here is my non-recursive solution.

sub mychomp { while (@_) { for (shift) { push @_, grep { ref || eval { defined && chomp; 0 }; } ref eq 'ARRAY' ? @$_ : ref eq 'HASH' ? values %$_ : ref eq 'SCALAR' ? $$_ : ref eq 'REF' ? $$$_ : $_ } } }

Of course even this is not complete as there could be a reference to a GLOB, which could contain a SCALAR, HASH and ARRAY. But who would use those :)

Replies are listed 'Best First'.
Re: Re: chomp any data structure recursively
by Juerd (Abbot) on Dec 21, 2001 at 19:44 UTC
    I thought I would comment because not one of the solutions given handle a reference to a reference. So here is my non-recursive solution.
    I forgot to handle references to references, will be fixed in a few minutes
    I also admit i forgot to test if it's defined, so I'll change that right away.
    Thanks!

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$