Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: chomp any data structure recursively

by gbarr (Monk)
on Dec 21, 2001 at 19:11 UTC ( [id://133765]=note: print w/replies, xml ) Need Help??


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:~$

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://133765]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2024-04-25 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found