I tried explaining my reasoning behind how I accessed the args in subs.
I've been looking into oop because in this script there's a lot of expect usage and I want to create re-uasable and well structured subs. (currently that'snot the case)
Below is a case where I have used shift.
In this case shift makes sense imo, although it could have just as well been written like this.sub set_timeout { my $self = shift; my $to = $self->{timeout}; if (@_){ $self->{timeout} = shift; } return $to; }
The reason I didn't use the index based assignment is that shift feels better here and in the documentation I read about oop they exclusively used shift accessing. However in a different scenario like below I don't think using shift in the if clause makes sense.sub set_timeout { my $self = $_[0]; my $to = $self->{timeout}; if ($_[1]){ $self->{timeout} = $_[1]; } return $to; }
So what I'm saying is I used shift when I felt like it without having a clue whether it's faster or better than index based assignment. =)sub set_stuff { my $self = shift; if (@_){ $self->{stuff1} = shift; #3 lines for one task $self->{stuff2} = shift; $self->{stuff3} = shift; ($self->{stuff1},$self->{stuff2},$self->{stuff3}) = @_; #1 lin +e, same result regardless of stuff presence } return 1; }
In reply to Re^5: RFC: beginner level script improvement (various comments)
by georgecarlin
in thread RFC: beginner level script improvement
by georgecarlin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |