[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Beginner's question



I have installed Perl 5 on my Mac G3 and I find the language fascinating
- especially regular expressions.

I just purchased MacPerl Power & Ease to answer a (probably silly)
question that has been bugging me.
The book pretty well dashed my hopes of using exec() or system() to pull
off what I want.

 The book did not mention eval() anywhere I could locate. I once thought
I'd conquered this thing some months ago using eval but the Perl system
crashed each time - possibly with a message about memory usage.

 My question: I'm a Scrabble player - tournaments & clubs & so on. In N.
America we have a specific list of legal words and I have a copy on my
Mac.

 I absolutely love regular expressions as a means of digging through
those words looking for this or that pattern. The little script below is
what I use and it does a great job - blindingly fast. But to run it each
time, I have to go in and tweak the part which right now happens to
contain /^lie..$/. So the cycle is, edit the line, press shift-command-R
to run it, jot down whatever I learn, press command-W to close the
output screen, get the cursor where I want it, the repeat.

 I can't for the life of me think of a way (that actually works) where I
could have a Perl program
 a) ask the user to input for any regular expression,
 b) read the whole file and print out any matches of that regular
expression, then
 c) go back to step a) without stopping, without relocating the edit
cursor, etc.

I feel that there must be an easy way here. With exec() or system() I
was going to print out a second script which did what I wanted and then
came back... but I guess this isn't looking too promising now. With
eval() I tried putting the crucial
line inside and running it "as a little Perl program" as another book
said it - but the whole system self-destructs.

 I'd appreciate any & all assistance.

---------------------------------------------------------------------------------

This works fine but there HAS to be a better way...

open (WORDSLIST,"WORD LIST for Perl a") || die "can't open wordlist:$!";

while ( defined ( $tester = <WORDSLIST>)) {
chomp ($tester);
if ($tester =~  /^lie..$/ ) { print "$tester\n"; };
}
close (WORDSLIST);
print "all done\n";





# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org