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

Re: What does this mean?

by Perlbotics (Canon)
on Aug 20, 2012 at 19:55 UTC ( #988498=note: print w/replies, xml ) Need Help??


in reply to What does this mean?

It's a common setter/getter idiom however with an unfortunate chosen method name setID.

'get' attribute: no argument given, so $id is undefined, current value of $self->{_id} is returned

my $id = $obj->setID(); # return current _id
'set' attribute (and 'get' new value at the same time)
my $new_id = $obj->setID( 42 ); # updates and returns new _id 42 # or just: $obj->setID( 42 );

Replies are listed 'Best First'.
Re^2: What does this mean?
by tobyink (Abbot) on Aug 20, 2012 at 22:24 UTC

    I don't know if it was necessarily intended to act as a getter+setter. It's probably just a setter that happens to include a quick check to prevent people from setting the ID to undef. It happens to also return the current ID, but I'd assume that's just incidental. A method needs to return something; might as well be something vaguely useful.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988498]
help
Chatterbox?
[Corion]: Nicholas Clark++ # read for a multichar block-delimiter by scanning for the last char, and only then check whether the whole delimiter was read.
[Corion]: At least if you're appending the data read to a larger buffer, this means you avoid the situation of "a delimiter was found but the other half has not been read yet"
choroba misses the context
[Corion]: choroba: Optimizing how Perl reads source code on startup (and then processes it line-by-line)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2016-12-06 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (107 votes). Check out past polls.