Nie jesteś zalogowany.
Jeśli nie posiadasz konta, zarejestruj je już teraz! Pozwoli Ci ono w pełni korzystać z naszego serwisu. Spamerom dziękujemy!
Prosimy o pomoc dla małej Julki — przekaż 1% podatku na Fundacji Dzieciom zdazyć z Pomocą.
Więcej informacji na dug.net.pl/pomagamy/.

Użytkownik


Witam
jak zmusić perla żeby drukował mi po polsku?
mam taki kawałek kodu:
#!/usr/bin/perl use warnings; use locale; $w = localtime time; print "$w\n";
to mi drukuje:
Mon Oct 17 18:58:05 2011
czyli po angielsku :(
w sysemie mam:
root@testsql:/usr/lib/cgi-bin# locale LANG=pl_PL.UTF-8 LC_CTYPE="pl_PL.UTF-8" LC_NUMERIC="pl_PL.UTF-8" LC_TIME="pl_PL.UTF-8" LC_COLLATE="pl_PL.UTF-8" LC_MONETARY="pl_PL.UTF-8" LC_MESSAGES="pl_PL.UTF-8" LC_PAPER="pl_PL.UTF-8" LC_NAME="pl_PL.UTF-8" LC_ADDRESS="pl_PL.UTF-8" LC_TELEPHONE="pl_PL.UTF-8" LC_MEASUREMENT="pl_PL.UTF-8" LC_IDENTIFICATION="pl_PL.UTF-8" LC_ALL=pl_PL.UTF-8 root@testsql:/usr/lib/cgi-bin# date pon, 17 paź 2011, 18:59:15
jak widać date mi drukuje po polsku. jak zmusić perla do tego samego??
Offline

Użytkownik


Spróbuj w ten sposób:
#!/usr/bin/perl
use warnings;
use POSIX qw(strftime);
$data=strftime("%c",localtime());
print $data;U mnie wydaje się działać...
Offline




Użyszkodnik
$ perldoc -f localtime
…
In scalar context, "localtime()" returns the ctime(3) value:
$now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
This scalar value is not locale dependent but is a Perl builtin. For GMT instead of local time use the "gmtime" builtin. See also
the "Time::Local" module (to convert the second, minutes, hours, ... back to the integer value returned by time()), and the POSIX
module's strftime(3) and mktime(3) functions.
To get somewhat similar but locale dependent date strings, set up your locale environment variables appropriately (please see
perllocale) and try for example:
use POSIX qw(strftime);
$now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;Offline