Alex Moen wrote: > > Hey all... > > Does anyone have any snippets lying around that will work > like grep? I know there's a built-in grep statement in > Perl, but the Camel book doesn't give a good enough example > for me to use. Basically, I want to (via a web page) grep > for any information that may be contained in a password file > entry: username, last name, phone number, etc. using one > field in a form and return all instances of the search > information entered back to a new web page. I have a finger > script that I have built, but I haven't successfully been > able to modify it, and it is too specific. > > For instance, I would like the search term "johnson" to > match the following: > > johnson:x:111:111:Robert > James,,555-1212:/home/users/johnson:/bin/passwd > mylogin:x:112:111:President > Johnson,,123-4567:/home/users/mylogin:/bin/passwd > johnsond:x:113:111:Bill > Rich,,654-3210:/home/users/johnsond:/bin/passwd > > Any takers on this? open FH, $file or die ... while (<FH>) { if (/$expr/) { # found a record with that expr } } # or you could read it into an array and use grep my @array = <FH>; my @finds - grep /$expr/, @array; close FH; Make sure you escape $expr properly if there are reserved chars in it. -- ,-/- __ _ _ $Bill Luebkert ICQ=14439852 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list. To unsubscribe go to http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users