Question: Please write a perl script, searchone.pl , that will search a given data file for a given pattern. Both the search pattern and the search
Please write a perl script, searchone.pl , that will search a given data file for a given pattern. Both the search pattern and the search file name should be provided from the command line as follow:
searchone.pl search-pattern search-file
$ ./searchone.pl pop /etc/services
$ ./searchone.pl imap /etc/services
Please don't give me something like below, because it doesn't work and not the solution:
#! /usr/bin/perl
#use the utf8 use utf8; use warnings;
#Declare input as for access the file@ input = < file > ; #Get the file name as input print "Please enter the name of the file: "; $filename = < STDIN > ; chop $filename;
#open the file open(my $DATA, "<:utf8", $filename) or die "Could not open the file!!: $!"; binmode STDOUT, ":utf8";
#Get the search pattern print 'Enter the pattern: '; chomp($pattern = < STDIN > );
#Get the string print 'Enter the String: '; chomp($input = < STDIN > );
#checks the input is equal to pattern or not if ($input = ~/$pattern/) {# Display statement print "true: The string is found in the file "; } else {# Display statement print "false: The string was not found in the file "; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
