Perl Programming humour for the geeks..
Posted: 30 July 03 2:16 pm
http://perl.plover.com/IAQ/IAQlist.html
Some of my favourites:
How do I clear the screen?
Use this function:
sub clear_the_screen {
print $ x 1_000_000;
}
What's a regular expression to replace 09:23:53 08-OCT-98 with Thu Oct 8 09:23:53 1998?
s{.*}{Thu Oct 8 09:23:53 1998}
How do I get tomorrow's date?
Use this function:
sub tomorrow_date {
sleep 86400;
return localtime();
}
How do I block warnings?
The simplest way is to do
close STDERR;
How do I get my perl program to run faster?
In Perl, there's always more than one way to do it. Try one of these techniques.
use more 'cpu';
use less 'time';
use more 'speed';
## or, the ever popular Military Marching Band accompaniment:
use March::Sousa qw(:DoubleTime);
The March::* hierarchy is not found on CPAN. Please contact the author for more information.
Alternatively, programs have been known to complete more quickly when they contain a declaration like this one:
BEGIN {exit}
If your application is truly urgent, you might try the experimental
no more 'time';
feature, but this has been reported to cause some systems to panic.
Perldoc isn't running properly. Where can I find the documentation?
perldoc perldoc
I have a lot of Bourne shell scripts I'd like to convert to Perl... What's the easiest way to do it?
Make sure that the first line of your script is #!/bin/sh. That magic comment tells the Perl interpreter to understand Bourne shell syntax.
I've got a C program I want to translate to Perl... How do I do that?
If you're using gcc, version 2.7 or better, you can use the translate-to-perl mode.
gcc -P -E foo.c > foo.pl
(gcc is smart enough to figure out that you want to convert to 'perl' by specifying the 'p' and 'e' alone.)
For versions of gcc prior to 2.7, use
gcc -larry -Wall foo.c > foo.pl
Some of my favourites:
How do I clear the screen?
Use this function:
sub clear_the_screen {
print $ x 1_000_000;
}
What's a regular expression to replace 09:23:53 08-OCT-98 with Thu Oct 8 09:23:53 1998?
s{.*}{Thu Oct 8 09:23:53 1998}
How do I get tomorrow's date?
Use this function:
sub tomorrow_date {
sleep 86400;
return localtime();
}
How do I block warnings?
The simplest way is to do
close STDERR;
How do I get my perl program to run faster?
In Perl, there's always more than one way to do it. Try one of these techniques.
use more 'cpu';
use less 'time';
use more 'speed';
## or, the ever popular Military Marching Band accompaniment:
use March::Sousa qw(:DoubleTime);
The March::* hierarchy is not found on CPAN. Please contact the author for more information.
Alternatively, programs have been known to complete more quickly when they contain a declaration like this one:
BEGIN {exit}
If your application is truly urgent, you might try the experimental
no more 'time';
feature, but this has been reported to cause some systems to panic.
Perldoc isn't running properly. Where can I find the documentation?
perldoc perldoc
I have a lot of Bourne shell scripts I'd like to convert to Perl... What's the easiest way to do it?
Make sure that the first line of your script is #!/bin/sh. That magic comment tells the Perl interpreter to understand Bourne shell syntax.
I've got a C program I want to translate to Perl... How do I do that?
If you're using gcc, version 2.7 or better, you can use the translate-to-perl mode.
gcc -P -E foo.c > foo.pl
(gcc is smart enough to figure out that you want to convert to 'perl' by specifying the 'p' and 'e' alone.)
For versions of gcc prior to 2.7, use
gcc -larry -Wall foo.c > foo.pl