At this point could a user still input something like 7mary3.  Ideally a
user can enter a name or several separated by commas but *nothing* else.
Convention would be lowercase firstinitiallastname  It seems like Rob's is
really close but I don't understand all of the code.  I am a little shy with
arrays.  Is @names built as you go? And, is the input all one element? It
seems to me as if that is the case but not 100% sure.


-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 09, 2003 10:43 AM
To: [EMAIL PROTECTED]
Subject: Re: regular expressions


Hi Paul

See below.

"Paul Kraus" <[EMAIL PROTECTED]> wrote in message
021b01c2b7f3$490ed540$64fea8c0@pkrausxp">news:021b01c2b7f3$490ed540$64fea8c0@pkrausxp...
> Correct me if I am wrong but wouldn't
> @names = sprit /,/,$ans;

That's pretty much what I did, except that I added optional leading and
trailing whitespace to the regex so that these would be trimmed from the
names. I didn't actually do the job properly though, because whitespace at
the start and end of $ans won't be removed, and input like '   Henrietta'
will fail. Nearly right though!

> Then you could perform your tests against the array elements.
> if (/[A-Za-z]+/)

Not really. That only checks to see if the name contains at least one alpha.
I did {/[^a-zA-Z]/ which checks for at least one non-alpha, when the loop
continues and reports an error. Also you don't need the '+' modifier.

> Assuming that the names would only contain those characters.
>
> or if (/\w+/) meaning all word characters.

/\W/ would do in my code, but its unwholesome inclusion of the underscore in
a valid 'word' character makes it much less useful for non-programming apps.

>
> Do the same thing. Splitting everything separated by a comma?

Unsure what you mean here :-? I'll pretend you didn't say it.

Cheers,

Rob

>
> > -----Original Message-----
> > From: Rob Dixon [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, January 09, 2003 10:06 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: regular expressions
> >
> >
> > Hello, erm, "Evan N Mr Niso/Lockheed Martin Kehayias"
> >
> > This should do what you want:
> >
> >
> >     my @names;
> >     do {
> >         errmesg() if @names;
> >         my $ans = <STDIN>;
> >         @names = split /\s*,\s*/, $ans;
> >     } while (grep {/[^a-zA-Z]/} @names);
> >
> > which splits on commas with any amount of preceding and
> > trailing whitespace. Names have to be alphabetic.
> >
> > HTH,
> >
> > Rob
> >
> >
> > "Evan N Mr Niso/Lockheed Martin Kehayias"
> > <[EMAIL PROTECTED]> wrote in message
> > 90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144">news:90AFE0B84E52EE46A8CD1DB0789C0A860ED043@DADC144...
> > > Greetings,
> > >
> > > I am attempting to limit entries a user could make when inputting
> > > names
> > into
> > > one of my scripts.  I prompt the user to enter one or more
> > names.  One
> > name
> > > is easy to isolate but when there are more I want to
> > support commas.
> > > At
> > the
> > > same time I don't want to accept anything other than names
> > and commas.
> > > I want to force the user to either enter names correctly or
> > exit.  For
> > > that matter it would be really cool if I could test the
> > names against
> > > /etc/passwd.  But beggars can't be choosers I will tackle the array
> > > piece later.
> > >
> > > What the user sees:
> > >
> > > Please enter user name(s):
> > > If more than one separate using commas
> > > example (single name): evan
> > > example (multi name): debbie, clint, henry
> > >
> > >
> > >
> > > So far what broken pieces I have...
> > >
> > > #!/usr/bin/perl
> > >
> > >
> > > while($ans !~ /^[a-z]+$/ || $ans !~ /^[a-z]+\,?[a-z]*$/) {
> > >   errmesg ();
> > >   $ans = <STDIN>;
> > >
> > > };
> > >
> > > sub errmesg {
> > >   print "\nType user name(s) and press enter:\n";
> > >   print "note: if more than one separate using commas\n";
> > >   print "example (single name): evan\n";
> > >   print "example (multi name): debbie, clint, henry\n";
> > > }
> > >
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to