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

Re: [MacPerl] Beginner's question



At 09:11 -0500 05-02-2000, Jeff Myers wrote:
> 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,

Why not use MacPerl::Ask? Look under the Help menu for 'Macintosh 
specific features':
	MacPerl::Ask(PROMPT, DEFAULT) =item MacPerl::Ask(PROMPT)
	Asks the user for a string. A default value may be given. 
Returns undef if the dialog is cancelled.

	Example:

	    $phone = MacPerl::Ask("Enter your phone number:");
	    $name  = MacPerl::Ask("Enter your first name", "Bruce");


> b) read the whole file and print out any matches of that regular
>expression, then

you worked that out fine. Maybe you can read the whole file in memory 
for speedier access.

> c) go back to step a) without stopping, without relocating the edit
>cursor, etc.

A do or while loop would suffice.

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

$rex="";
do {
	$rex = MacPerl::Ask("Enter a regularexp", $rex);
	while ( defined ( $tester = <WORDSLIST>)) {
		chomp ($tester);
		if ($tester =~  /$rex/ ) { print "$tester\n"; };
	}
} until length($rex) == 0;
close (WORDSLIST);
print "all done\n";

__END

You could even provide the answer in the same dialog box that asks 
for the next input. RTFM for that.

Good luck Scrabbling.
P.S. I haven't tested the variable in the m// part, but that should work.


Axel

_____________________________
Axel M. Roest                | AXEL Development & Support
info@axel.nu                 | Macintosh developer & UNIX sysadmin
http://www.axel.nu           | 42

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