[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: : Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: : : : Personally I don't know which of all the date related modules : : that would fit best, but I'm sure others do. I for one wouldn't : : use any module: : : : : my $time = time; : : : : sub mydate { : : my $days = (shift or 0); : : my ($d, $m, $y) = (localtime($time - $days * 86400))[3..5]; : : sprintf '%02d.%02d.%02d', $m + 1, $d, $y % 100; : : } : : : : print 'Today: ', mydate(), "\n"; : : print 'Yesterday: ', mydate(1), "\n"; : : : : so is the shift or 0 statement doing the opposite of push / pop : calls do?
That depends on your definition of "opposite". Read perlfunc "shift" for details. : shift deletes elements of a list or an array? : : $x = (2,3,4); : $y = shift ($x); # y is now 3,4 That doesn't run. my @x = (2, 3, 4); # @x = (2, 3, 4) my @y = shift @x; # @y = (2) and @x = (3, 4) : why is the or 0 needed It is a default in case no argument was passed. : b/c with just my $days = 0 the whole : subroutine does not work ! ! ?? Yes it does. (At least it works on my machine.) As written: Today: 08.17.04 Yesterday: 08.16.04 With my $days = 0: Today: 08.17.04 Yesterday: 08.17.04 Which is what is expected. When $days equals zero, nothing is subtracted from the current time which returns today's date from the sub. It is equivalent to using mydate(0) with the original sub. HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>