X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq4.pod;h=326ec9180be4398a5cd77afdbe134f55532f6539;hb=92a24ac3df5779ed0c9681cafefdd31fc6e1ae98;hp=38a0e91328e5137ab1afcb8a7639addb024df960;hpb=e573f90328e9db84c5405db01c52908bfac9286d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index 38a0e91..326ec91 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 7954 $) +perlfaq4 - Data Manipulation ($Revision: 10394 $) =head1 DESCRIPTION @@ -17,7 +17,7 @@ exactly. Some real numbers lose precision in the process. This is a problem with how computers store numbers and affects all computer languages, not just Perl. -L show the gory details of number representations and +L shows the gory details of number representations and conversions. To limit the number of decimal places in your numbers, you can use the @@ -362,17 +362,16 @@ pseudorandom generator than comes with your operating system, look at =head2 How do I get a random number between X and Y? -To get a random number between two values, you can use the -C builtin to get a random number between 0 and +To get a random number between two values, you can use the C +builtin to get a random number between 0 and 1. From there, you shift +that into the range that you want. -C returns a number such that -C<< 0 <= rand($x) < $x >>. Thus what you want to have perl -figure out is a random number in the range from 0 to the -difference between your I and I. +C returns a number such that C<< 0 <= rand($x) < $x >>. Thus +what you want to have perl figure out is a random number in the range +from 0 to the difference between your I and I. -That is, to get a number between 10 and 15, inclusive, you -want a random number between 0 and 5 that you can then add -to 10. +That is, to get a number between 10 and 15, inclusive, you want a +random number between 0 and 5 that you can then add to 10. my $number = 10 + int rand( 15-10+1 ); @@ -491,14 +490,14 @@ give you the same time of day, only the day before. print "Yesterday was $yesterday\n"; -You can also use the C module using its Today_and_Now +You can also use the C module using its C function. use Date::Calc qw( Today_and_Now Add_Delta_DHMS ); my @date_time = Add_Delta_DHMS( Today_and_Now(), -1, 0, 0, 0 ); - print "@date\n"; + print "@date_time\n"; Most people try to use the time rather than the calendar to figure out dates, but that assumes that days are twenty-four hours each. For @@ -517,12 +516,11 @@ Can you use your pencil to write a non-Y2K-compliant memo? Of course you can. Is that the pencil's fault? Of course it isn't. The date and time functions supplied with Perl (gmtime and localtime) -supply adequate information to determine the year well beyond 2000 -(2038 is when trouble strikes for 32-bit machines). The year returned -by these functions when used in a list context is the year minus 1900. -For years between 1910 and 1999 this I to be a 2-digit decimal -number. To avoid the year 2000 problem simply do not treat the year as -a 2-digit number. It isn't. +supply adequate information to determine the year well beyond 2000 and +2038. The year returned by these functions when used in a list +context is the year minus 1900. For years between 1910 and 1999 this +I to be a 2-digit decimal number. To avoid the year 2000 +problem simply do not treat the year as a 2-digit number. It isn't. When gmtime() and localtime() are used in scalar context they return a timestamp string that contains a fully-expanded year. For example, @@ -535,6 +533,15 @@ not the language. At the risk of inflaming the NRA: "Perl doesn't break Y2K, people do." See http://www.perl.org/about/y2k.html for a longer exposition. +=head2 Does Perl have a Year 2038 problem? + +No, all of Perl's built in date and time functions and modules will +work to about 2 billion years before and after 1970. + +Many systems cannot count time past the year 2038. Older versions of +Perl were dependent on the system to do date calculation and thus +shared their 2038 bug. + =head1 Data: Strings =head2 How do I validate input? @@ -1006,9 +1013,16 @@ C, and C modules. (contributed by brian d foy) -For example, I'll use a string that has two Perl scalar variables -in it. In this example, I want to expand C<$foo> and C<$bar> to -their variable's values. +If you can avoid it, don't, or if you can use a templating system, +such as C or C