iamsachin has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm new to perl. I searched online,reffered to a couple of links and i have written a perl script to match multiple sting in a file. this is the file :
{ 'testing' => {
link => "http://www.espn.com",,
bandwidth => "100",
r => "2",
}, };10 15 * * * cd /tmp; /path/to/file --timeslot 'name'
Now,I need to write a perl script that matches the string in the file.
find_string { my ($file, $string) = @_; open my $fh, '<', $file; while (<$fh>) { return 1 if /\Q$string/; } die "Unable to find string: $string"; } find_string('filename', "testing");
The above script searches the file for string "testing" in the file and fails if the string is not found. Now I'd like to search multiple strings in that file like bandwidth,rate. I guess i need to use regular expressions.But i'm not sure how to implement it. any suggestions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl regular expressions
by kennethk (Abbot) on Jun 23, 2014 at 21:44 UTC | |
by iamsachin (Initiate) on Jun 23, 2014 at 23:25 UTC | |
by kennethk (Abbot) on Jun 23, 2014 at 23:30 UTC | |
by iamsachin (Initiate) on Jun 23, 2014 at 23:52 UTC | |
by kennethk (Abbot) on Jun 24, 2014 at 00:06 UTC | |
| |
by iamsachin (Initiate) on Jun 23, 2014 at 23:50 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 14:04 UTC | |
by kennethk (Abbot) on Jun 24, 2014 at 18:28 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 23:58 UTC | |
by kennethk (Abbot) on Jun 25, 2014 at 14:44 UTC | |
|
Re: perl regular expressions
by AppleFritter (Vicar) on Jun 23, 2014 at 22:06 UTC | |
by iamsachin (Initiate) on Jun 23, 2014 at 23:29 UTC | |
by AppleFritter (Vicar) on Jun 23, 2014 at 23:41 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 18:47 UTC | |
by AppleFritter (Vicar) on Jun 24, 2014 at 19:00 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 19:25 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 19:43 UTC | |
by AppleFritter (Vicar) on Jun 24, 2014 at 20:16 UTC | |
by iamsachin (Initiate) on Jun 25, 2014 at 00:02 UTC | |
by AppleFritter (Vicar) on Jun 25, 2014 at 22:56 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 14:20 UTC | |
by AppleFritter (Vicar) on Jun 24, 2014 at 17:36 UTC |