=head1 NAME
-perlfaq - frequently asked questions about Perl ($Date: 2005/01/31 15:52:15 $)
+perlfaq - frequently asked questions about Perl ($Date: 2005/03/27 07:21:21 $)
=head1 DESCRIPTION
=item *
-How can I generate simple menus without using CGI or Tk?
-
-=item *
-
How can I make my Perl program run faster?
=item *
=head1 NAME
-perlfaq3 - Programming Tools ($Revision: 1.46 $, $Date: 2005/02/13 02:36:09 $)
+perlfaq3 - Programming Tools ($Revision: 1.47 $, $Date: 2005/03/27 07:21:22 $)
=head1 DESCRIPTION
online manpages at
http://www-users.cs.umn.edu/%7Eamundson/perl/perltk/toc.html .
-=head2 How can I generate simple menus without using CGI or Tk?
-
-The http://www.cpan.org/authors/id/SKUNZ/perlmenu.v4.0.tar.gz
-module, which is curses-based, can help with this.
-
=head2 How can I make my Perl program run faster?
The best way to do this is to come up with a better algorithm. This
=head1 NAME
-perlfaq4 - Data Manipulation ($Revision: 1.60 $, $Date: 2005/02/14 18:24:01 $)
+perlfaq4 - Data Manipulation ($Revision: 1.61 $, $Date: 2005/03/11 16:27:53 $)
=head1 DESCRIPTION
=head2 How do I find the day or week of the year?
-The localtime function returns the day of the week. Without an
+The localtime function returns the day of the year. Without an
argument localtime uses the current time.
$day_of_year = (localtime)[7];
sub get_century {
return int((((localtime(shift || time))[5] + 1999))/100);
}
+
sub get_millennium {
return 1+int((((localtime(shift || time))[5] + 1899))/1000);
}
=head1 NAME
-perlfaq6 - Regular Expressions ($Revision: 1.30 $, $Date: 2005/02/14 18:25:48 $)
+perlfaq6 - Regular Expressions ($Revision: 1.31 $, $Date: 2005/03/27 07:17:28 $)
=head1 DESCRIPTION
=head2 Why does using $&, $`, or $' slow my program down?
-Once Perl sees that you need one of these variables anywhere in
-the program, it provides them on each and every pattern match.
-The same mechanism that handles these provides for the use of $1, $2,
-etc., so you pay the same price for each regex that contains capturing
-parentheses. If you never use $&, etc., in your script, then regexes
-I<without> capturing parentheses won't be penalized. So avoid $&, $',
-and $` if you can, but if you can't, once you've used them at all, use
-them at will because you've already paid the price. Remember that some
-algorithms really appreciate them. As of the 5.005 release. the $&
-variable is no longer "expensive" the way the other two are.
+(contributed by Anno Siegel)
+Once Perl sees that you need one of these variables anywhere in the
+program, it provides them on each and every pattern match. That means
+that on every pattern match the entire string will be copied, part of
+it to $`, part to $&, and part to $'. Thus the penalty is most severe
+with long strings and patterns that match often. Avoid $&, $', and $`
+if you can, but if you can't, once you've used them at all, use them
+at will because you've already paid the price. Remember that some
+algorithms really appreciate them. As of the 5.005 release, the $&
+variable is no longer "expensive" the way the other two are.
+
=head2 What good is C<\G> in a regular expression?
You use the C<\G> anchor to start the next match on the same
=head1 NAME
-perlfaq7 - General Perl Language Issues ($Revision: 1.21 $, $Date: 2005/01/21 12:10:22 $)
+perlfaq7 - General Perl Language Issues ($Revision: 1.22 $, $Date: 2005/03/27 07:19:01 $)
=head1 DESCRIPTION
This is like this
------------ ---------------
- $foo{line} $foo{"line"}
- bar => stuff "bar" => stuff
+ $foo{line} $foo{'line'}
+ bar => stuff 'bar' => stuff
The final semicolon in a block is optional, as is the final comma in a
list. Good style (see L<perlstyle>) says to put them in except for
=head2 What does "bad interpreter" mean?
+(contributed by brian d foy)
+
The "bad interpreter" message comes from the shell, not perl. The
actual message may vary depending on your platform, shell, and locale
settings.
right path to perl (or any other program capable of running scripts).
Sometimes this happens when you move the script from one machine to
another and each machine has a different path to perl---/usr/bin/perl
-versus /usr/local/bin/perl for instance.
+versus /usr/local/bin/perl for instance. It may also indicate
+that the source machine has CRLF line terminators and the
+destination machine has LF only: the shell tries to find
+/usr/bin/perl<CR>, but can't.
If you see "bad interpreter: Permission denied", you need to make your
script executable.