Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: What is the purpose of '||=' in the example code for Spreadsheet::XLSX

by tobyink (Abbot)
on Nov 14, 2012 at 20:05 UTC ( #1003887=note: print w/ replies, xml ) Need Help??


in reply to What is the purpose of '||=' in the example code for Spreadsheet::XLSX

"My guess is that if MaxRow or MaxCol are undefined then they are set to equal MinRow or MinCol respectfully."

Very close. But it's not if they're undefined. It's if they're false. Undefined things are false, but so is 0, and so is the empty string, and so can be objects which overload boolification.

The //= operator would do what you originally suggested. It specifically checks undefinedness, not falseness.

The //= operator was introduced in Perl 5.10, so people wanting to do defined-or-assign while supporting ancient versions of Perl are forced to choose between ||= (which might not be quite what they want - maybe they need to differentiate between undef and 0) or a more longwinded:

$sheet->{MaxRow} = $sheet->{MinRow} unless defined $sheet->{MaxRow};
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: What is the purpose of '||=' in the example code for Spreadsheet::XLSX
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-09-22 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (185 votes), past polls