On Tue, Sep 10, 2002 at 06:27:32PM -0400, Orr, Chuck (NOC) wrote:
> Hello,
>> I have something that looks like this:
>> if (grep("$KEY",EXISTING)){
>> In the event that this is true, I want to print the data that makes it true.
> In other words, I want to print the line from EXISTING that contains the
> pattern from the variable $KEY. The problem I am having is figuring out
> where that line is. Is it stored in a variable I don't know about? If not,
> how can I obtain this data? I realize this is a pretty basic question, but
> I am having a tough time finding the answer and I need to get this done.
> Any suggestions/help would be greatly appreciated.
You should capture the output of grep into an array:
@a = qw(one two three four twenty);
if (@found = grep (/tw/, @a)) {
print "Found: @found\n";
} else {
print "Didn't find\n";
}
Chris
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org