O
O. Olson
Hi,
I am for most part familiar C++/Java programming - but not much with
Perl. I am trying to figure out if I can use C style structures in
Perl - they are not classes per se - but sort of similar.
In the following code - which is part of a larger program - I tried
to group the hours, minutes and seconds of time into a combined data
structure. However once I set the current time ($curr_time) - the next
midnight time ($next_midnight) gets changed. Can anyone guess why??
As I said I am not much into Perl - so I might be doing something
obviously wrong.
-------------------------------------------------------------------
use warnings;
use strict;
# Declaration of a data structure that would hold a single line or
record of the file
# This would ensure that the file would never remain open if the
program exits prematurely
my $time = {
HOUR => my $hour,
MINUTE => my $minute,
SECOND => my $second
};
# Defining two variables of the type time
my $curr_time = $time; #Contains the hour, minute, second
my $next_midnight = $time; #Contains the hour, minute, second
# Setting the Next Midnight Time
($next_midnight->{HOUR}, $next_midnight->{MINUTE}, $next_midnight-
# Setting the current time
($curr_time->{SECOND}, $curr_time->{MINUTE}, $curr_time->{HOUR}) =
localtime();
print "curr_time Time: "; &printTime($curr_time); print "\n";
print "But now, Next Midnight Time: "; &printTime($next_midnight);
print "\n";
# This function would print the time variable passed on to it, without
adding a new line character to it
sub printTime()
{
# Declaring a temporary time variable
my $temp_time = $time;
$temp_time = $_[0];
print "$temp_time->{HOUR}:$temp_time->{MINUTE}:$temp_time-
------------------------------------------------------------
Console Output:
Next Midnight Time: 23:59:58
curr_time Time: 22:50:12
But now, Next Midnight Time: 22:50:12
---------------------------------------------------------
Why did "Next Midnight Time" change?
Thanks to all who help,
O.O.
I am for most part familiar C++/Java programming - but not much with
Perl. I am trying to figure out if I can use C style structures in
Perl - they are not classes per se - but sort of similar.
In the following code - which is part of a larger program - I tried
to group the hours, minutes and seconds of time into a combined data
structure. However once I set the current time ($curr_time) - the next
midnight time ($next_midnight) gets changed. Can anyone guess why??
As I said I am not much into Perl - so I might be doing something
obviously wrong.
-------------------------------------------------------------------
use warnings;
use strict;
# Declaration of a data structure that would hold a single line or
record of the file
# This would ensure that the file would never remain open if the
program exits prematurely
my $time = {
HOUR => my $hour,
MINUTE => my $minute,
SECOND => my $second
};
# Defining two variables of the type time
my $curr_time = $time; #Contains the hour, minute, second
my $next_midnight = $time; #Contains the hour, minute, second
# Setting the Next Midnight Time
($next_midnight->{HOUR}, $next_midnight->{MINUTE}, $next_midnight-
print "Next Midnight Time: "; &printTime($next_midnight); print "\n";{SECOND}) = (23, 59, 58);
# Setting the current time
($curr_time->{SECOND}, $curr_time->{MINUTE}, $curr_time->{HOUR}) =
localtime();
print "curr_time Time: "; &printTime($curr_time); print "\n";
print "But now, Next Midnight Time: "; &printTime($next_midnight);
print "\n";
# This function would print the time variable passed on to it, without
adding a new line character to it
sub printTime()
{
# Declaring a temporary time variable
my $temp_time = $time;
$temp_time = $_[0];
print "$temp_time->{HOUR}:$temp_time->{MINUTE}:$temp_time-
}{SECOND}";
------------------------------------------------------------
Console Output:
Next Midnight Time: 23:59:58
curr_time Time: 22:50:12
But now, Next Midnight Time: 22:50:12
---------------------------------------------------------
Why did "Next Midnight Time" change?
Thanks to all who help,
O.O.