Within an Perl object’s method I would like to call another method on a list of variables. Using map like so does not work:
($open, $high, $low, $close)
= map( $self->adjust_for_factor, ($open, $high, $low, $close) );
….
sub adjust_for_factor {
my $self = shift;
my $price = shift;
return $price * $self->get_factor ;
}
This works, however its ugly and doesn’t scale. I’m sure it must be possible to use map here:
($open, $high, $low, $close)
= ( $self->adjust_for_factor($open)
, $self->adjust_for_factor($high)
, $self->adjust_for_factor($low)
, $self->adjust_for_factor($close) );
I guess it’s an issue of referencing self in the correct way. I’m having trouble conceptualizing how it all fits together.
Thanks to all who take the time to consider/ leave feedback.
As @tchrist said, you forgot to pass
$_to your method. The correct way would beYou can also modify the method so that it can accept a list: