Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
No such thing as a small change
 
PerlMonks  

Re^2: ||= in Hash Slice

by Brovnik (Hermit)
on Jan 06, 2009 at 12:15 UTC ( #734417=note: print w/ replies, xml ) Need Help??


in reply to Re: ||= in Hash Slice
in thread ||= in Hash Slice

Yup, I guess that works, but I was hoping for something a bit more elegant.

@{$audit}{@$copy_fields} = map { $item->{$_} || '' } @$copy_fields;
Is probably the nearest I'll get.
P.S. The '' vs. 0 difference is irrelevant here in my case, I just want avoid undefs.


Comment on Re^2: ||= in Hash Slice
Download Code
Re^3: ||= in Hash Slice
by Bloodnok (Vicar) on Jan 06, 2009 at 17:56 UTC
    That may not, probably won't, work in all cases ... consider when the value of $item->{$_} is 0: in this case, the wanted value of 0 will be overwritten by the empty string, since $item->{$_} is, from a perl POV, false. Hence Corions suggestion, tho' not quite what you were seeking, is better.

    A user level that continues to overstate my experience :-))

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2014-04-21 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls