Harry Putnam wrote:
> 
> "John W. Krahn" <[EMAIL PROTECTED]> writes:
> 
> > printf " %02d/%02d/%04d %02d:%02d:%02d\n", $lta[4] + 1, $lta[3], $lta[5] + 1900, 
>@lta[2,1,0];
> 
> Thanks.. the tips work good.  And I overlooked the part about mnths
> being 0-11.
> 
> I get the idea from your posted printf line and learned a new trick
> with the @ar[2,4,7] syntax you used but couldn't really understand why it
> gave a screwball year in my script until I noticed the `=' missing in
> $lta[5] + 1900.
> 
> Still not sure I understand why it needs to be there.
> 
> cat test2
> 
>   #!/usr/local/bin/perl -w
>   $now = time;
> 
>   $date_spec = ($now - 86400);
>   # local time adjusted
>   @lta = localtime($date_spec);

The value in $lta[5] is now 102.


>   $mnth = ($lta[4] + 1);
>   print " $mnth/$lta[3]/" . ($lta[5] += 1900) . " $lta[2]:$lta[1]:$lta[0]\n";

The value in $lta[5] has been modified to 2002, the += operator modifies
the original value.


>   print localtime() . "\n";
>   printf " %02d/%02d/%04d %02d:%02d:%02d\n", $lta[4] + 1, $lta[3], $lta[5] + 1900, 
>@lta[2,1,0];

You are now adding 1900 to 2002 so it prints 3902.  Either don't modify
$lta[5] and just add 1900 to it each time or modify it once and use that
value everywhere.


> OUTPUT:
>   $ ./test2
>    12/15/2002 20:16:38
>   Mon Dec 16 20:16:38 2002
>    12/15/3902 20:16:38


  @lta = localtime($date_spec);
  $lta[4] += 1;     # modify month
  $lta[5] += 1900;  # modify year

  print " $lta[4]/$lta[3]/$lta[5] $lta[2]:$lta[1]:$lta[0]\n";
  print localtime() . "\n";
  printf " %02d/%02d/%04d %02d:%02d:%02d\n", @lta[4,3,5,2,1,0];




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to