[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] wantarray() Function Question



The Code:

#!perl =#-w

print "\n";
my(@the_Time) = &hms();
print ("The Time is Hour: $the_Time[0], Minutes: $the_Time[1], 
Seconds $the_Time[2]." . "\n");

my($the_Time) = &hms();
print ("The Time is  $the_Time." . "\n");


sub hms {
	my($sec, $min, $hr) = localtime ();

	if (wantarray()) {
		print "\n" . "Array - hms()" . "\n";
		return ($hr, $min, $sec);
	} else {
		print "\n" . "String - hms()" . "\n";
		return (sprintf ("%02d.%02d.%02d", $hr, $min, $sec));
	}
}


The expected Result:

Array - hms()
The Time is Hour: 21, Minutes: 41, Seconds 5.

String - hms()
The Time is  21.41.07.


The actual Result:

Array - hms()
The Time is Hour: 21, Minutes: 41, Seconds 5.

Array - hms()
The Time is  21.


If I change:

my($the_Time) = &hms();

to

my($the_Time);
$the_Time = &hms();

... I am rewarded with the expected Result.


Question:

Can anyone tell me why?


Samuel

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org