Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: chomp any data structure recursively

by runrig (Abbot)
on Dec 21, 2001 at 01:51 UTC ( [id://133630]=note: print w/replies, xml ) Need Help??


in reply to Re: chomp any data structure recursively
in thread chomp any data structure recursively

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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-18 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found