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

Re: Convert undef to empty string in a hash

by GrandFather (Saint)
on Jan 16, 2015 at 00:03 UTC ( [id://1113414]=note: print w/replies, xml ) Need Help??


in reply to Convert undef to empty string in a hash

Quicker is really unlikely to be an issue. "Better" is much harder to define. You may consider one of:

$_ //= '' for values %foo; $foo{$_} //= '' for keys %foo;

"better". I'd tend toward the first because it's maybe a little more obvious that it's the values in the hash that you are processing.

For the most part when thinking about "better", think about "is the intent of this code obvious?". Make the code clear first, then if you really need to, make it faster. Almost always you don't need to do the "make it faster" bit.

If you do think you need to make it faster, first write unit tests then profile the code before changing anything. Unit tests to make sure you don't break the code while changing it. Profile so you don't waste your time "fixing" stuff that isn't broken.

Perl is the programming world's equivalent of English

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found