Re: Mnemonic Devices for Perl Programming
by blakem (Monsignor) on Nov 16, 2001 at 04:20 UTC
|
my mnemonic for /s and /m is:
/s -- Allows .* to Slurp up numerous lines
/m -- Allows ^ and $ to match in the Middle of the string
-Blake
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
And now everyone knows why I got to be mentioned in the same breath as merlyn and Erudil. dotSlurp1 mode indeed... ;-)
But seriously, go check out japhy's book... Its a really good read and goes into some new regex stuff that I didn't know much about.
1dotSlurp was coined by dws as a summary of my mnemonic. kind of catchy really...
-Blake
| [reply] [Watch: Dir/Any] |
|
Re (tilly) 1: Mnemonic Devices for Perl Programming
by tilly (Archbishop) on Nov 16, 2001 at 02:50 UTC
|
My favorite is, "Hash-lookup is read, 'of'"
This helps enormously when figuring out how to name hashes. Try it.
If you want to create some for /m and /s, you could do worse than, To match many lines, /m and There is a single character "." doesn't match, unless you /s. | [reply] [Watch: Dir/Any] |
Re: Mnemonic Devices for Perl Programming
by halxd2 (Monk) on Nov 16, 2001 at 03:01 UTC
|
use strict or die;
took me a long time to see the wisdom! | [reply] [Watch: Dir/Any] [d/l] |
Re: Mnemonic Devices for Perl Programming
by brianarn (Chaplain) on Nov 16, 2001 at 06:31 UTC
|
Well, one thing I used to forget a lot was to make sure I successfully opened a filehandle properly, cause it'd cause my code to die in a funny way, so I reminded myself to
open FH, "< blah.txt" or die "Can't open file: $!";
and I could never remember what the special variable was, until I came up with the thought that, when I cause I program to die like this, I'm taking it out with a bang.
<rimshot here>
~Brian | [reply] [Watch: Dir/Any] [d/l] |
Re: Mnemonic Devices for Perl Programming
by Sweeper (Pilgrim) on Nov 16, 2001 at 02:55 UTC
|
The /s modifier Simplifies the
Silly Signification of dot:
"everything except \n", how Silly!
"everything", how much Simpler!
The /m modifier allows ^ and $
to Match even in the Middle of a string.
How this help. It certainly has helped me.
| [reply] [Watch: Dir/Any] |
Re: Mnemonic Devices for Perl Programming
by TheDamian (Vicar) on Nov 17, 2001 at 07:16 UTC
|
| [reply] [Watch: Dir/Any] |
Re: Mnemonic Devices for Perl Programming
by Biker (Priest) on Nov 16, 2001 at 13:41 UTC
|
Well, I certainly didn't invent this classic, but I do apply it to Perl programming just as often as for many other daily tasks.
KISS -- Keep It Simple, Stupid!
f--k the world!!!!
/dev/world has reached maximal mount count, check forced.
| [reply] [Watch: Dir/Any] |
Re: Mnemonic Devices for Perl Programming
by demerphq (Chancellor) on Nov 16, 2001 at 21:01 UTC
|
Not real sure if this is a mnemoic, but a rule of thumb that I find useful when explaining the behaviour of chained maps and other list functions is
Maps make more sense when read right to left.
OT:I remember learning the color codes for resistors in electronics class in high school. The teacher gave us a contrived mnemoic which frankly I could never keep in my head. I was saved however by an electronics book from years before which had the rather saucy menomic
Bad Boys Raped Our Young Girls But Violette Gave Willingly
Which I have never managed to forget. :-)
Yves / DeMerphq
--
Have you registered your Name Space? | [reply] [Watch: Dir/Any] |
Re: Mnemonic Devices for Perl Programming
by George_Sherston (Vicar) on Nov 16, 2001 at 20:56 UTC
|
I hadn't thought of this, but it's quite a useful thing to do. I have to look up my Perl 5 pocket reference every time I do seek because I have a mental block abt whether the position comes before or after the whence (somehow it makes more sense that it shd come after, actually)... the trouble is, I can't actually think up a snappy mnenomic for FPW. The best I cd do was appropriate for foulmouthed people who don't like accountants, viz **** Price Waterhouse. The asterisks are fine because I know the filehandle comes first ;-). But perhaps the process of looking for a mnenomic will break my blockage and I'll be able to remember anyhow.
§ George Sherston | [reply] [Watch: Dir/Any] [d/l] |
|
#!/usr/bin/perl
use strict;
my ($string, $num) = @ARGV;
my ($DICT) = '/usr/share/dict/words';
my (%words, @chs, $ch, $line, $i);
@chs = split('', $string);
for $ch (@chs) {
if (!defined($words{$ch})) { $words{$ch} = []; }
}
if (!open(IN, $DICT)) { print STDERR "\nError:$DICT\n\n"; exit; }
while (chomp ($line = <IN>)) {
$ch = substr($line, 0, 1);
if (defined($words{$ch})) { push (@{$words{$ch}}, $line); }
}
for ($i = 0; $i < $num; $i++) {
for $ch (@chs) {
print "$words{$ch}->[rand(@{$words{$ch}})] ";
}
print "\n";
}
| [reply] [Watch: Dir/Any] [d/l] |
|
Hm, "Seek Fortune, Passion, and Wisdom"?
Thanks,
James Mastros,
Just Another Perl Scribe
| [reply] [Watch: Dir/Any] |
Re: Mnemonic Devices for Perl Programming
by belg4mit (Prior) on Jan 25, 2002 at 06:00 UTC
|
| [reply] [Watch: Dir/Any] |