Question: Write a perl script, searchtwo.pl, that will search a given data file for a given pattern. Both the search pattern and the search file name

Write a perl script, searchtwo.pl, that will search a given data file for a given pattern. Both the search pattern and the search file name should be obtained from the prompted inputs as the examples shown below:

$ ./searchtwo.pl

Enter a data file name: /etc/services

Enter a search pattern: pop

$ ./searchtwo.pl

Enter a data file name: /etc/services

Enter a search pattern: imap

Please don't give me code below as an answer, it doesn't work and not the solution:

#! /usr/bin/perl

use utf8; use warnings; @in = ; print "Please enter the name of the file: " ; $file = ; chop $file;

open(my $DATA, "<:utf8", $file) or die "Could not open the file!!: $!"; binmode STDOUT, ":utf8";

print 'Enter the pattern: '; chomp($pat = );

print 'Enter the String: '; chomp($in = );

if ($in =~ /$pat/) { print "true: The string is found "; } else { print "false: The string was not found "; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!