Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

"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'

In reply to Re: What is the purpose of '||=' in the example code for Spreadsheet::XLSX by tobyink
in thread What is the purpose of '||=' in the example code for Spreadsheet::XLSX by vt220

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found