in reply to Using RETURN in a sub
Just a few snooty comments on style:
my @days = qw(Sun Mon Tues Wed Thurs Fri Sat); my @mons = qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec);
If EXPR is omitted, localtime() uses the current time (localtime(time)).
my ($mday,$mon,$year,$wday) = (localtime)[3..6];
This tends to result in clearer code since you don't have to search in a sea of undefs to find the variables.
You could quite simply do:$date = "$days[$wday] $mons[$mon] $mday $year"; return $date;
return "$days[$wday] $mons[$mon] $mday $year";
Put all of that together and you get:
sub makeDate { my @days = qw(Sun Mon Tues Wed Thurs Fri Sat); my @mons = qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec); my ($mday,$mon,$year,$wday) = (localtime)[3..6]; $year += 1900; return "$days[$wday] $mons[$mon] $mday $year"; }
You may wish to read perldoc perlsub for information concerning the different ways of calling subroutines, perldoc perlstyle for recommended code formatting (just for a guideline until you can develop your own style), and perldoc perldata for more information about perl data types and how they can be accessed.
|
|---|