develooper Front page | perl.beginners | Postings from March 2002

RE: Comparing to many possibles

Thread Previous | Thread Next
From:
Jeff 'japhy' Pinyan
Date:
March 4, 2002 13:31
Subject:
RE: Comparing to many possibles
Message ID:
Pine.GSO.4.21.0203041629100.20827-100000@crusoe.crusoe.net
On Mar 4, Timothy Johnson said:

>  I still am not convinced that all of the hoopla about \z is really
>necessary.  I guess the question I need answered before I go back and change
>anything is this:  How is the user supposed to enter an extra \n without
>exiting the prompt?  What I mean is, the only situation in which this could
>make a difference is if you concede that a user can somehow enter a \n
>character into a prompt without returning that value back to your script.
>Otherwise it's your fault if you don't chomp their response.

If I am asked how to convert

  if ($x eq 'y' or $x eq 'z') { ... }

to a regex, I will give the correct answer:

  if ($x =~ /^[yz]\z/) { ... }

Using $ changes the range of accepted answers.  That is why I use \z
instead of $.  If the question asked was something like "how can I see if
the user entered 'y' or 'z' as input?" I would probably use $ because
there is no way of determining whether the person asking has chomp()ed or
not.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About