newbie2perl has asked for the wisdom of the Perl Monks concerning the following question:
Thanks in advance for any help on this, look forward to hearing what you have to say!use strict; my ($Filename, @array, $searchstring, @stringsfound, @file); print "Please enter the name of the file:"; $Filename = <STDIN>; chomp($Filename); $Filename = "C:\\Perl\\".$Filename; open IN, $Filename or die "Could not open file $!"; @file = <IN>; close(IN); @array = ('file', 'this', 'dog', 'forward'); foreach (@file){ foreach $searchstring (@array) { if (m/(.*?)$searchstring/i) { push @stringsfound, $searchstring; } } } print @stringsfound;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Match a string only once in a file
by tirwhan (Abbot) on Mar 08, 2005 at 00:11 UTC | |
|
Re: Match a string only once in a file
by shemp (Deacon) on Mar 07, 2005 at 23:41 UTC | |
|
Re: Match a string only once in a file
by tall_man (Parson) on Mar 08, 2005 at 00:40 UTC | |
by Roy Johnson (Monsignor) on Mar 08, 2005 at 01:10 UTC | |
|
Re: Match a string only once in a file
by Roy Johnson (Monsignor) on Mar 08, 2005 at 01:05 UTC | |
|
Re: Match a string only once in a file
by Zaxo (Archbishop) on Mar 08, 2005 at 02:32 UTC | |
|
Re: Match a string only once in a file
by Roy Johnson (Monsignor) on Mar 08, 2005 at 01:49 UTC | |
|
Re: Match a string only once in a file
by hsinclai (Deacon) on Mar 07, 2005 at 23:59 UTC | |
by Roy Johnson (Monsignor) on Mar 08, 2005 at 01:19 UTC | |
by hsinclai (Deacon) on Mar 08, 2005 at 04:18 UTC | |
|
Re: Match a string only once in a file
by webengr (Pilgrim) on Mar 08, 2005 at 00:16 UTC | |
by tall_man (Parson) on Mar 08, 2005 at 00:44 UTC |