Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Difference between my $self = shift and my ($self) = @_

by topher (Scribe)
on Feb 22, 2013 at 06:27 UTC ( #1020075=note: print w/replies, xml ) Need Help??

in reply to Difference between my $self = shift and my ($self) = @_

As tobyink pointed out, there's no difference in what ends up in $self, but there is a big difference in what's left in @_. If your subroutine isn't expecting arguments, then you can use either method without concern. If you are going to be taking arguments, then you have a choice to make.

Personally, I'm a big fan of using my $self = shift;. For me, it makes the code cleaner and more mentally straightforward. When using shift, the contents of @_ end up being exactly the same as the arguments I passed to the subroutine. If I use assignment from @_, then I have to constantly account for that $self at the first position, complicating things.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020075]
[LanX]: better try 3
[shmem]: that python stuff is none of my business.
[shmem]: but sometimes I have to debug things implemeted by "the other team" and stick their nose into their dirt.
[shmem]: because it affects "my team"
[shmem]: ah well... git is incomplete. There are commands missing:
[shmem]: git stop crap
[shmem]: for instance

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-03-20 18:35 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (257 votes). Check out past polls.