in reply to RE: Trying to make a search
in thread Trying to make a search

this won't fulfill the original author's requirement of matching lines that _begin_ with a certain letter. you're missing the '^' at the beginning of your regular expression.

also, why does everyone but me just assume in their solution that user will be well-behaved and only enter a single letter? i know we're not writing production code here, but it seems a little odd to me that i was the only one to bother to do 'substr $input, 0, 1'.

one thing i liked that no one else remembered to do was turnstep's use of the 'o' regular expression modifier to only compile the regexp once.

Replies are listed 'Best First'.
RE: RE: RE: Trying to make a search
by takshaka (Friar) on Jun 05, 2000 at 00:57 UTC
    also, why does everyone but me just assume in their solution that user will be well-behaved and only enter a single letter? i know we're not writing production code here, but it seems a little odd to me that i was the only one to bother to do 'substr $input, 0, 1'.

    Perhaps it is a bleed-over of Perl's DWIM concept. It seems logical (to me, at least) that if the user inputs a string rather than a single character the program should return all lines beginning with that string. But then I imagine it is just as logical to you that the program should only use the first character as the search prefix.

    In legitimate production code where we are concerned about how many characters the user inputs, it would probably be better to allow only one character--rather than an entire line--to be input in the first place (don't want to confuse those end-users). And since the OP does say 'letter', we'd also reject any input that isn't one.