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

Re: What does this mean?

by linuxkid (Sexton)
on Aug 20, 2012 at 21:00 UTC ( #988510=note: print w/replies, xml ) Need Help??

in reply to What does this mean?

if ya want it even shorter, try $self->{_id} = defined($id) ? $id : $self->{_id}


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

    If by "shorter," you mean 14 characters longer, then absolutely.

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Re^2: What does this mean?
by Anonymous Monk on Aug 21, 2012 at 07:04 UTC
    defined $id and $$self{_id} = $id; or with newer perls $$self{_id} //= $id;
      $$self{_id} //= $id; checks the definedness of $$self{_id}, not of $id (as the other suggested snippets do), so it does something completely different (never reset the attribute, instead of prevent assignment of an undefined id).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988510]
[Corion]: :-D
[ww]: or a lot more than (22*2) for /me
[ww]: er -- senior cognitive deficiency: ((22+(22*2))
[ww]: (but pls don't s/senior/senile/ ... not yet
[karlgoethebier]: A bit more audience now: The Impact of Information Sources on Code Security Very interesting IMHO...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2017-09-25 14:37 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (280 votes). Check out past polls.