Thanks to all who replied - it is working fine now and I am now moving on to 
the next problem....all your help was appreciated and very usefull.  I am sure 
I will be back here soon.
 
Thanks
Mark

________________________________

From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: Wed 20/09/2006 17:07
To: Perl Beginners
Subject: Re: Newbie Question



M K Scott wrote:
> Hi,

Hello,

> I have tried that to no avail.  I have also tried a simple match
> of !~ m/(m|f){1}/ and even put in the code you suggested to read
> !~ m/^(m|f){1}$/ but this still doesn't work properly.   Input of
> "d" or "T" will work to say it is incorrect and input of "m" or
> "f" will be accepted but I was under the impression that the {1}
> would limit it to only accept a single character while in practice
> it still accepts "ff" and "mmm".   Any ideas?

The expression above seems to work for me:

$ perl -le'
for ( qw/ a aa aaa f ff fff m mm mmm / ) {
    print "$_: ", !/^(m|f){1}$/ ? "NOT " : "", "found";
    }
'
a: NOT found
aa: NOT found
aaa: NOT found
f: found
ff: NOT found
fff: NOT found
m: found
mm: NOT found
mmm: NOT found

Note that /^(m|f){1}$/ could also be written as /^[mf]$/.


> One further question though, an example question I am doing asks
> for a text file to be read in and the number of digits to be
> counted (ie 3 "1"'s, 6 "2"'s etc) and I can read input in and do
> a 'getc' and pattern match that against a hash containing word
> references to the numbers and then add one to a count but is
> this the best way to do this?

Using getc() is usually not the best way to do anything in Perl.




John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to