in reply to Matching 2 Keywords to retreve information
Using the following data file (phonebook.txt):
You could write something likeJon:1:0123456789 Rob 1 0987654321 Sean 4 075312468 Tom-3-0111 222 333 Colin 3 0222 111 5555
Then if you type#! /usr/bin/perl my ($username,$userid) = @ARGV; undef @ARGV; my @phonebook = (<>); @phonebook = grep /\b$username\b/ , @phonebook; @phonebook = grep /\b$userid\b/ , @phonebook; print foreach(@phonebook);
You will get Jon:1:0123456789 Hope this helps,cat phonebook.txt | match.pl Jon 1
JJ
Update:
I do realise that the above code still has bugs, I'm just trying to give our brother Monk some pointers. For a more robust solution, you should really define a file format (e.g. colon-sperated values), then you could use split to ensure you are only matching against the right fields.
|
|---|