X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq4.pod;h=af08e473ee7480adfa684acc3251b32fbd6b8d76;hb=e77edca30a2be27033e243f6b69dee5191c27b5a;hp=b641d5845e5e04705bf866d3848e8d3d5f7d8249;hpb=5f8d77f137e503ce8824c31ce9f3a5e8bd4ec726;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index b641d58..af08e47 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.40 $, $Date: 2003/01/26 17:43:21 $) +perlfaq4 - Data Manipulation ($Revision: 1.44 $, $Date: 2003/07/28 17:35:21 $) =head1 DESCRIPTION @@ -316,7 +316,7 @@ Get the http://www.cpan.org/modules/by-module/Roman module. If you're using a version of Perl before 5.004, you must call C once at the start of your program to seed the random number generator. - BEGIN { srand() if $[ < 5.004 } + BEGIN { srand() if $] < 5.004 } 5.004 and later automatically call C at the beginning. Don't call C more than once---you make your numbers less random, rather @@ -353,12 +353,33 @@ C =head1 Data: Dates -=head2 How do I find the week-of-the-year/day-of-the-year? +=head2 How do I find the day or week of the year? -The day of the year is in the array returned by localtime() (see -L): +The localtime function returns the day of the week. Without an +argument localtime uses the current time. - $day_of_year = (localtime(time()))[7]; + $day_of_year = (localtime)[7]; + +The POSIX module can also format a date as the day of the year or +week of the year. + + use POSIX qw/strftime/; + my $day_of_year = strftime "%j", localtime; + my $week_of_year = strftime "%W", localtime; + +To get the day of year for any date, use the Time::Local module to get +a time in epoch seconds for the argument to localtime. + + use POSIX qw/strftime/; + use Time::Local; + my $week_of_year = strftime "%W", + localtime( timelocal( 0, 0, 0, 18, 11, 1987 ) ); + +The Date::Calc module provides two functions for to calculate these. + + use Date::Calc; + my $day_of_year = Day_of_Year( 1987, 12, 18 ); + my $week_of_year = Week_of_Year( 1987, 12, 18 ); =head2 How do I find the current century or millennium? @@ -741,6 +762,19 @@ case", but that's not quite accurate. Consider the proper capitalization of the movie I, for example. +Damian Conway's L module provides some smart +case transformations: + + use Text::Autoformat; + my $x = "Dr. Strangelove or: How I Learned to Stop ". + "Worrying and Love the Bomb"; + + print $x, "\n"; + for my $style (qw( sentence title highlight )) + { + print autoformat($x, { case => $style }), "\n"; + } + =head2 How can I split a [character] delimited string except when inside [character]? Several modules can handle this sort of pasing---Text::Balanced, @@ -2003,8 +2037,9 @@ and C functions: =head2 How do I print out or copy a recursive data structure? The Data::Dumper module on CPAN (or the 5.005 release of Perl) is great -for printing out data structures. The Storable module, found on CPAN, -provides a function called C that recursively copies its argument. +for printing out data structures. The Storable module on CPAN (or the +5.8 release of Perl), provides a function called C that recursively +copies its argument. use Storable qw(dclone); $r2 = dclone($r1);