All my variables are declared following my $var format.
In my program I call mainMethod()
Then in mainMethod I define a DateTime variable and then pass it to a separate helper method 3 times.:
my ($day,$month,$year)=(localtime)[3,4,5];
my $dt = DateTime->new(
year => $year,
month => 2 + $month,
day => 1,
hour => 8,
minute => 30,
time_zone => 'America/New_York'
);
helper($dt, $year, $month, $day,);
helper($dt,$year, $month, $day,);
helper($dt,$year, $month, $day,);
In helper I start with:
my $date = $_[0];
my ($year, $month, $day) = ($_[1],$_[2],$_[3]);
This method does a lot of different things but the only changes I make to $date is $date = $date->add(days => (3 - $date->day_of_week) % 7);
The problem is, it seems like the changes I make $date in my helper method, persist through each time I call the method from mainMethod Note: I'm not returning anything
For example, if $dt was instead 5 and helper was $date + 2 I would get
helper($dt) #output: 7
helper($dt) #output: 9
helper($dt) #output: 11
Instead of the expected 5 for every response.
Is there some step that I'm missing to reset those variables at the end of the method?