sreek3502 has asked for the wisdom of the Perl Monks concerning the following question:
have the below code, and its input file "fruits.txt" has following values.
Apple Mango Grapes Bananas Avocado
I'm getting the output as below;
Grapes not in list Strawberry not in list Grapes not in list Strawberry not in list Grapes Strawberry not in list Grapes not in list Strawberry not in list Grapes not in list Strawberry not in list Grapes not in list Strawberry not in list
However, i'm actually looking for an output like this, please help!
Expected result as follows.
Grapes Strawberry not in list
use strict; use warnings; open (FILE,"fruits.txt"); while (<FILE>) { if (/Grapes/) { print $_; } else { print "Grapes not in list\n";} if (/strawberry/i) { print $_; } else { print "Strawberry not in list\n"; } } close FILE;
2018-03-23 Athanasius added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print only the matched line when process line by line from a file
by davido (Cardinal) on Mar 21, 2018 at 19:10 UTC | |
|
Re: Print only the matched line when process line by line from a file
by NetWallah (Canon) on Mar 21, 2018 at 20:49 UTC | |
|
Re: Print only the matched line when process line by line from a file
by stevieb (Canon) on Mar 21, 2018 at 19:13 UTC | |
|
Re: Print only the matched line when process line by line from a file
by BillKSmith (Monsignor) on Mar 21, 2018 at 22:28 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |