programming-examples/perl/Subroutine/Return more than one value from subroutine.pl

17 lines
429 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/bin/perl -w
use strict;
my ($hours, $minutes, $seconds) = second2HourMinuteSecond(999);
print "999 seconds is $hours hours, $minutes minutes and $seconds seconds";
print "\n";
sub second2HourMinuteSecond {
my ($h,$m);
my $seconds = shift;; # defaults to shifting @_
$h = int($seconds/(60*60));
$seconds %= 60*60;
$m = int($seconds/60);
$seconds %= 60;
($h,$m,$seconds);
}